2010-12-01 66 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 

參見接近底部的說明。刪除逗號,你很好。事情正在改善(如上面鏈接文章所述),但爲了在野外最大程度地兼容,您需要再觀看一段時間。

(其他音符是題外話,但同樣,強烈建議解決了那些爲好,從未依靠插入分號。)