1

I have a problem when trying to get JSON data with Ajax and on Internet Explorer only.

I'm using this jQuery code :

$.ajax({
    type: "GET",
    url: "./ajaxglobal/chargementcommandes", 
    cache: false,
    dataType: "json",
    contentType: "application/json",
    success: function(data) {
        alert("Success : "+data);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert("Error : "+textStatus+" / "+errorThrown);
    }
});

With "chargementcommandes" being a PHP/Zend page.

The PHP code of "chargementcommandes", simplified for testing, is the following :

echo '[
        { "data" : "A node", "children" : [ { "data" : "Only child", "state" : "closed" } ], "state" : "open" },
        "Ajax node"
]';

Everything is working fine in Firefox and Chrome (I get the expected data), but in Internet Explorer (tested in IE8 and IE9), I get "Success : undefined" from the alert. So the Ajax call doesn't return anything. I tried many things but I didn't succeed to get rid of this issue.

Any help would be greatly appreciated. Thanks in advance !

EDIT : Added type, cache and contenttype in jQuery code. Still "Success : undefined" response...

  • With what `Content-Type` the server is responding? – raina77ow Oct 15 '12 at 16:35
  • I hope this solution could help you (it works for me) http://stackoverflow.com/questions/2037412/ajax-call-from-jquery-works-in-firefox-but-not-in-ie8 – juan.obando Oct 16 '12 at 03:17
  • I've edited my Ajax code, to ensure that the content-type is ok and that no cache is used : `$.ajax({ type: "GET", url: "./ajaxglobal/chargementcommandes", cache: false, dataType: "json", contentType: "application/json", success: function(data) { alert("Success : "+data); }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert("Error : "+textStatus+" / "+errorThrown); } });` I still have "Success : undefined". – Yoann Léorier Oct 16 '12 at 11:10

1 Answers1

0

Make sure the headers are correct, for the json response, as raina77ow suggested.

The correct header for json is "application/json", this header is set like this:

header('Content-type: application/json');

mclemme
  • 81
  • 1
  • 1