gpt4 book ai didi

jQuery Ajax 总是返回 "undefined"?

转载 作者:行者123 更新时间:2023-12-01 02:17:00 25 4
gpt4 key购买 nike

  function getThisFrame(frameId) {
var r;
$.ajax({
type: "POST",
contentType: "application/json",
url: "abcdefg.asmx/RetriveThis",
data: "{Id:" + Id + "}",
dataType: 'json',
success: function (result) {
return result.d
}
});
}

返回值总是“未定义”?我该如何解决这个问题?谢谢!

数据肯定没问题!

最佳答案

您将 result.d 返回到 $.ajax() 而不是 getThisFrame()

如果你想以某种方式处理result.d,你需要某种回调。

function getThisFrame(frameId, callback) {
var r;
$.ajax({
type: "POST",
contentType: "application/json",
url: "abcdefg.asmx/RetriveThis",
data: "{Id:" + Id + "}",
dataType: 'json',
success: function (result) {
if(typeof callback === 'function') callback.apply(this, [result.d]);
}
});
}

getThisFrame(5, function(data){
// do something with data.
});

关于jQuery Ajax 总是返回 "undefined"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3203283/

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