简体   繁体   中英

How to get json response of third party domain using jsonp or jquery.getjson

I am new to this web programming.I want to get json response of third party domain in javascript.So that I tried with Ajax http request but it is only for same domain.So that I am trying using jsonp and jquery.getjson.Still I am not getting any result please help me.

code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>get json in alert</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$.getJSON("http://cricketapi.mblogi.com/sfsjson.php?callback=?", function(result){
   //response data are now in the result variable
   alert(result);
});
</script>
</head>
<body>


</body>
</html> 

You will need to ensure that the URL you are using is returning data in json format.

For example, updating your code to access a Flickr feed:

$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?ids=8623220@N02&format=json&jsoncallback=?", function(result){
   //response data are now in the result variable
   alert(result);
});

The key here is at the end of the URL, &format=json&jsoncallback=? which tells the Flickr server to send back json data.

So the solution for you is to update the URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM