Skip to content

Instantly share code, notes, and snippets.

@zzuhan
Created October 24, 2012 16:36
Show Gist options
  • Save zzuhan/3947191 to your computer and use it in GitHub Desktop.
Save zzuhan/3947191 to your computer and use it in GitHub Desktop.
simple ajax
$('#loading').ajaxStart(function () {
$(this).show();
});
$('#loading').ajaxStop(function () {
$(this).hide();
});
$('#send').click(function () {
// 我们先传递给其 callback 的name 然后其返回一个函数的调用,数据在参数中
// jQuery18206735994638875127_1350706129349(data);
// 返回来的是对回调函数的执行,传入了需要的参数
$.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?tags=car&tagmode=any&format=json&jsoncallback=?', function (data) {
$('#resText').empty();
$.each(data.items, function (i, item) {
$('<img class="para"/>')
.attr('src', item.media.m)
.appendTo($('#resText'));
if (i==3) { return false; }
});
});
});
<div id="loading">加载中...</div>
<button id="send">发送</button>
<div id="resText">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment