Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with JSON in Internet Explorer 7

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

like image 677
feronovak Avatar asked Feb 10 '11 10:02

feronovak


1 Answers

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)

like image 107
Daniel Avatar answered Oct 26 '22 23:10

Daniel