2010-12-01 62 views
2
$.ajax({ 
    type: 'POST', 
    url: URL +'/foo/', 
    data: {'pass': pass}, 
    dataType: "json", 
    jsonp:'jsonp_callback', 
    success: function(data) { 
    if (data["success"] === "false") { 
     $("#password").val(""); 
     $('.error-message').removeClass('hide') 
     $('.error-message').addClass('show') 
    } 
    else { 
     var tempUrl="http://10.0.1.101:9000/bar/" 
     location.href=tempUrl; 
    } 
    }, 
}); 
return false 

这在Mozilla,Chrome,Safari中工作正常。但不是在IE中。可能是什么原因。我从服务器返回suucess值。如果成功为True,它将重定向到tempUrl。 但在IE浏览器中没有任何内容。看来,Ajax在IE中完全不起作用。为什么IE和Ajax有这么多问题?

+2

请注明IE的你对测试哪个版本(S)。 (IE很糟糕,但IE6比IE8糟糕得多)。 – Spudley 2010-12-01 11:40:37

+0

你看到任何javascript错误? – Heikki 2010-12-01 11:42:33

回答

0

你应该在这行的末尾添加分号:

$('.error-message').removeClass('hide') 
$('.error-message').addClass('show') 
var tempUrl="http://10.0.1.101:9000/bar/" 
4

您正在运行到“晃来晃去逗号”的问题(你success参数闭幕}后面的逗号)。 IE不喜欢对象文字中的悬挂逗号,它将它们视为语法错误,并且脚本死亡。 (这不是IE错误,这是对先前规范的合理解释;但最新的规范特别允许使用逗号,并且这在IE8中已得到修复。)焦虑:IE有一个类似但不同的问题在数组文字中悬挂逗号(仍然在IE8中)。

更多关于这两个isuses this article,但基本上是:

$.ajax({ 
    type: 'POST', 
    url: URL +'/foo/', 
    data: {'pass': pass}, 
    dataType: "json", 
    jsonp:'jsonp_callback', 
    success: function(data) { 
    if (data["success"] === "false") { 
     $("#password").val(""); 
     $('.error-message').removeClass('hide') // <== Strongly recommend ; here 
     $('.error-message').addClass('show')  // <== Another ; here 
    } 
    else { 
     var tempUrl="http://10.0.1.101:9000/bar/" // <== Another ; here 
     location.href=tempUrl; 
    } 
    }, // <== This comma is the problem 
}); 
return false         // <== Another ; here 

参见接近底部的说明。删除逗号,你很好。事情正在改善(如上面链接文章所述),但为了在野外最大程度地兼容,您需要再观看一段时间。

(其他音符是题外话,但同样,强烈建议解决了那些为好,从未依靠插入分号。)