使用Ajax从PHP+;Zend不只在IE中工作
我在尝试使用Ajax和Internet Explorer获取JSON数据时遇到了一个问题 我正在使用以下jQuery代码:使用Ajax从PHP+;Zend不只在IE中工作,php,jquery,ajax,json,internet-explorer,Php,Jquery,Ajax,Json,Internet Explorer,我在尝试使用Ajax和Internet Explorer获取JSON数据时遇到了一个问题 我正在使用以下jQuery代码: $.ajax({ type: "GET", url: "./ajaxglobal/chargementcommandes", cache: false, dataType: "json", contentType: "application/json", success: function(data) { a
$.ajax({
type: "GET",
url: "./ajaxglobal/chargementcommandes",
cache: false,
dataType: "json",
contentType: "application/json",
success: function(data) {
alert("Success : "+data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("Error : "+textStatus+" / "+errorThrown);
}
});
“chargementcommandes”是一个PHP/Zend页面
“chargementcommandes”的PHP代码简化为测试代码,如下所示:
echo '[
{ "data" : "A node", "children" : [ { "data" : "Only child", "state" : "closed" } ], "state" : "open" },
"Ajax node"
]';
在Firefox和Chrome中,一切都很正常(我得到了预期的数据),但在InternetExplorer中(在IE8和IE9中测试),我从警报中得到了“Success:undefined”。因此Ajax调用不会返回任何内容。我尝试了很多方法,但没有成功地解决这个问题
任何帮助都将不胜感激。
提前谢谢
编辑:在jQuery代码中添加了类型、缓存和contenttype。仍然是“Success:undefined”响应…确保json响应的头是正确的,正如raina77ow所建议的那样 json的正确标题为“application/json”,该标题的设置如下:
header('Content-type:application/json')代码>服务器响应的内容类型是什么?我希望这个解决方案可以帮助您(它对我很有用)我编辑了我的Ajax代码,以确保内容类型是正确的,并且没有使用缓存:$.Ajax({Type:“GET”,url:“./ajaxglobal/chargementcommandes”,cache:false,dataType:“json”,contentType:“application/json”,成功:函数(data){alert(“成功:“+data”);},错误:函数(XMLHttpRequest,textStatus,errorshown){alert(“错误:“+textStatus+”/”+errorshown);}});
我仍然有“成功:未定义”。