2011-02-10 133 views
16

IE8/Chrome,FF工作正常,但Internet Explorer 7讓我頭疼。Internet Explorer 7中的JSON問題

我試圖讓數字結果爲實際的形式

$(".checklist label").click(function() { 
    checkResults(); 
}); 

function checkResults() { 
    var str = $("form").serializeArray(); 
    $.ajax({ 
     type: "POST", 
     url: "/data.asmx/GetTotal", 
     cache: false, 
     contentType: "application/json; charset=utf-8", 
     data: JSON.stringify({ data: str }), 
     dataType: "json", 
     success: handleHtml, 
     error: ajaxFailed 
    }); 
} 

function handleHtml(msg) { 
    $("#result").text(msg.d); 
} 

function ajaxFailed(xmlRequest) { 
} 

我做了什麼不對的IE7不會工作?

謝謝

回答

30

JSON.stringify不是IE7的一部分。

你將不得不使用道格拉斯Crockford的JavaScript實現的是:

https://github.com/douglascrockford/JSON-js

更具體地說,本腳本:

https://github.com/douglascrockford/JSON-js/blob/master/json2.js

這將添加字符串化和分析方法的瀏覽器這不是本地實現此(如IE7及以下)

+5

順便說一句,你不必使用js在stringify上,作爲$ .ajax中的數據參數,您可以使用整個對象。 – MarrLiss 2011-02-10 11:01:25