Problem with JSON in Internet Explorer 7

feronovak picture feronovak · Feb 10, 2011 · Viewed 21.3k times · Source

IE8/Chrome,FF work well but Internet Explorer 7 is giving me headaches.

I am trying to get numeric result for actual form

$(".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) {
}

What have I done wrong that IE7 wont work?

Thanks

Answer

Daniel picture Daniel · Feb 10, 2011

JSON.stringify is not part of IE7.

You'll have to use Douglas Crockford's JavaScript implementation of this:

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

More specifically this script:

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

It will add the stringify and parse methods to browser that do not natively implement this (like IE7 and below)