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://www.ptt.cc/bbs/Ajax/M.1397671256.A.B14.html
討論串 (同標題文章)
完整討論串 (本文為第 3 之 3 篇):