我发送ajax调用并从第一个ajax获得我需要的答案,然后我想将我的结果传递给我的嵌套ajax,我的var(result)为null嵌套的ajax/settimeout的乐趣,我可以通过它吗?我错过了什么吗?如何将变量从ajax传递给嵌套的ajax
$.ajax({
url: '@Url.Action("getCustomerGuidId", "Document")',
type: 'POST',
cache: false,
data: { "classNum": currentclassNum},
contentType:'json' ,
dataType:'text',
success: function (result) {
alert(result);**-> is fine - not null**.
// a or result is null when I hit the getCurrentDoc- function althought I get the data I need from getCustomerGuidId function
var a = result;-> tried to pass it to a new var..IDK.. I
thought it will help... it didn't.
setTimeout(function() {
$.ajax({
type: "GET",
url: '@Url.Action("getCurrentDoc", "Document")',
contentType:'text',
data: a,-> here it's null
success: function (data) {
}
});
}, 2000);
},
error: function (result) {
alert("fail " + result);
}
});
在的setTimeout ,函数上下文得到了改变,这就是为什么a在那里是空的。 –