作者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/m.aspx?n=bbs/Ajax/M.1397671256.A.B14.html