我确定来自服务器的JSON是有效的(手动进行ajax调用),但我真的很想使用JQuery。我还确定使用萤火虫发送到服务器的“发布”网址是正确的。但是,错误回调仍然被触发(parsererror)。我也尝试过数据类型:文本。无法从JQuery接收JSON ajax调用
我还有其他选择吗?
$(function() {
$("#submit").bind("click", function() {
$.ajax({
type: "post",
url: "http://myServer/cgi-bin/broker" ,
datatype: "json",
data: {'start' : start,'end' : end},
error: function(request,error){
alert(error);
},
success: function(request) {
alert(request.length);
}
}); // End ajax
}); // End bind
}); // End eventlistener
非常感谢您花时间回答。它是我作为数据类型的dataType选项 – 2008-09-17 03:41:18
只需要注意,将dataType设置为“json”会自动将contentType设置为“application/json”。 – bhollis 2008-09-20 04:00:23
@BHR +1根据文档正确。然而,也许有用的要注意:我正在使用jquery 1.6.4 atm,并发现我需要明确设置contentType:“application/json; charset = utf-8” – zack 2012-02-14 18:15:07