gpt4 book ai didi

javascript - ajax成功操作后的对象引用错误 - jquery

转载 作者:行者123 更新时间:2023-11-30 18:31:55 25 4
gpt4 key购买 nike

在上面的 ajax 调用中,对象 jData 返回 null .. 但如果显示成功则成功返回对象:

var jData = null;

function x() {

$.ajax({
url : 'http://...",
success : function(data) {
jData = data;
alert(jData); // displays the object
}


});
return jData; //returns null ??
};

最佳答案

$.ajax() 是异步的。您必须在成功回调中直接使用 jData

var jData = null;

function x() {
$.ajax({
url : "http://...",
success : function(data) {
jData = data;
alert(jData); // displays the object
//do stuff here
}
});
}

关于javascript - ajax成功操作后的对象引用错误 - jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9414338/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com