Quantcast
Channel: Библиотека знаний
Viewing all articles
Browse latest Browse all 1318

jquery ajax to retrieve JSON data from remote URL

$
0
0

jquery ajax to retrieve JSON data from remote URL

1

test.json

<scripttype="text/javascript">
function getJSON(json) {
    alert("Got JSON!");
    // do something with json
}
</script><scripttype="text/javascript"src="http://192.168.99.68/test.json?callback=getJSON" async="true"></script>

2

<divid="images"> 
</div>
$.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",{
    tags:"gulmarg",
    tagmode:"any",
    format:"json"},function(data){
    $.each(data.items,function(i,item){
      $("<img/>").attr("src", item.media.m).appendTo("#images");if( i ==5)returnfalse;});});

3

$.jsonp({"url": target_url+"ping.php?callback=?","success":function(data){// print out data},"error":function(d,msg){// error}});
<?phpecho$_GET['callback'].'('."{'response' : 'success'}".')';?>

https://github.com/jaubourg/jquery-jsonp


Viewing all articles
Browse latest Browse all 1318