[英]why data is showing undefined in ajax
我正在调用ajax调用,其中向数组提供数据,当我要在控制台中调试此代码时向我显示data
undefined
为什么?
In the success
function of your first ajax call, you have this: 在您的第一个ajax调用的
success
功能中,您具有以下功能:
success: function (response) {
orderId = data;
if (data != null) {
orderStatus = "Order has been placed successfully.";
}
}
Note that you've called the argument to the callback response
, but then used data
. 请注意,您已经调用了回调
response
的参数,但是随后使用了data
。 The code as quoted should fail with a ReferenceError
, because there's no data
in scope in that callback (the only place you have var data
is inside another callback). 该代码引述应该会失败,并
ReferenceError
,因为没有data
在该回调范围(你所拥有的唯一的地方var data
是另一个回调内部 )。 I assume you have it declared in code you haven't quoted. 我假设您已经在未引用的代码中声明了它。
I assume you meant response
, not data
: 我认为您的意思是
response
,而不是data
:
success: function (response) {
orderId = response;
if (response != null) {
orderStatus = "Order has been placed successfully.";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.