Php JSON输出“;“未定义”;在Internet Explorer中,而不是在其他浏览器中

Php JSON输出“;“未定义”;在Internet Explorer中,而不是在其他浏览器中,php,json,internet-explorer,Php,Json,Internet Explorer,----------这是testA.php------------------------- [{"msgCD":"OK","msgSTR":"Hi"}] $(document).ready(function(){ $('.submit').click(function(){ $.getJSON('testA.php',function(data){ $.each(data,function(i,n){ $('#message').append(n['msgCD']+

----------这是testA.php-------------------------

[{"msgCD":"OK","msgSTR":"Hi"}]
$(document).ready(function(){ $('.submit').click(function(){
$.getJSON('testA.php',function(data){
    $.each(data,function(i,n){ 
        $('#message').append(n['msgCD']+'</br>');
    });
});
return false;});});
----------这是testB.html-------------------------

[{"msgCD":"OK","msgSTR":"Hi"}]
$(document).ready(function(){ $('.submit').click(function(){
$.getJSON('testA.php',function(data){
    $.each(data,function(i,n){ 
        $('#message').append(n['msgCD']+'</br>');
    });
});
return false;});});
$(文档).ready(函数(){$('.submit')。单击(函数()){
$.getJSON('testA.php',函数(数据){
$.each(数据,函数(i,n){
$(“#消息”).append(n['msgCD']+'
”; }); }); 返回false;});});


对于Chrome和firefox,JSON输出“HI”,但是IE,它根本不工作!!!OMG:(

您将一个对象包装到数组中,因此无法直接访问该对象:

var foo = [{"msgCD":"OK","msgSTR":"Hi"}]
foo.msgCD // undefined
foo[0].msgCD // "OK"
编辑:
我还建议您使用chrome控制台,只需制作一个控制台。log(n)你可以浏览你的对象。

如果你在IE中打开
F12
,看看会发生什么?同时检查你的html标记可能是问题的原因,检查所有html标记是否正确格式化,或者不是愚蠢的问题,但是你的php脚本返回的标题提到json(而不是文本/html)?另一件事可能是您的调用在html完成加载之前完成,并且#消息在dom中还不存在,或者类似的事情。