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...

3
  • With what Content-Type the server is responding? Commented Oct 15, 2012 at 16:35
  • I hope this solution could help you (it works for me) stackoverflow.com/questions/2037412/… Commented Oct 16, 2012 at 3: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". Commented Oct 16, 2012 at 11:10

1 Answer 1

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');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.