[英]Jquery Ajax callback
I've got an ajax call via jquery that executes without error until I get to the callback. 我有一个通过jquery进行的ajax调用,该调用将无错误执行,直到到达回调为止。 The content returned looks like this:
返回的内容如下所示:
{"UPSELLABLE":true,"OFFERTEXT":"p47r.cfm"}
Simply doing alert(upselldata); 只需做警报(upselldata); will alert the data above.
将提醒上面的数据。 But if I try access variable upselldata like a javascript object( I thought jquery did the eval work for me already ), the variables are undefined.
但是,如果我尝试像javascript对象那样访问变量upselldata(我认为jquery已经为我完成了eval的工作),则变量是不确定的。 See code below:
参见下面的代码:
$.ajax({
type: "POST",
datatype: "json",
data: "ProductID=1",
url: '/templates/public/upsell_available.cfm',
success: function(upselldata) {
alert(upselldata.UPSELLABLE); // upselldata.upsellable is undefined!?!?!
}
});
Use "dataType" not "datatype". 使用“数据类型”而不是“数据类型”。 Javascript is case-sensitive, therefore, jQuery is ignoring your setting.
Javascript区分大小写,因此jQuery忽略了您的设置。
Note that jQuery can auto-detect the type of data if you set the the headers properly in the response (I assume you are sending it back as text). 请注意,如果您在响应中正确设置标头,则jQuery可以自动检测数据类型(我假设您将其作为文本发送回去)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.