作者reso ()
看板Ajax
标题Re: [问题] JQuery ajax返回值传递问题
时间Thu Apr 17 02:00:53 2014
function doSameThing(data) {
在这里更新你的 HTML
}
$(document).ready(function () {
var foo;
$.ajax({
url: 'getsamething'
}).done(function (data) {
foo = data;
doSameThing(data); // 在这里把直传给 function 才是正确作法
});
// 在非同步中,foo 有时会是 undefined
// 所以别这麽做
doSameThing(foo);
});
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.41.38.249
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Ajax/M.1397671256.A.B14.html