1

Just today I noticed I have a major issue with IE..

I have a loop that receives various details about the system and user every 5 seconds, and updates values on the page as necessary. I build the query just by checking for required values in the HTML such as:

var query = '?name=value&other=bar';
if($('input.something').attr('checked') == 'checked') {
   query += '&more=info';                      
}  

After building the query, i use $.get to retrieve the information:

$.get('json_builder.php' + query, function(callback) {
   alert(callback);
});

My callback is a JSON string that I convert to an object using $.parseJSON(callback); and I use the object to access my data.

I get the alert with the JSON callback on ALL browsers except IE, in IE I get "undefined".

BUT, the request passes through, as in the developer tools section I see that the response is actually there, but for some reason the variable "callback" is left "undefined".

I've tried using $.getJSON instead of $.get - same result.

5
  • Have you tried using $.ajax call instead of the get shortcut? I have had some issues with get and post in the past while ajax call worked fine. Commented Aug 29, 2012 at 9:23
  • Yes I've tried using it without the shortcut, but to no avail.. Commented Aug 29, 2012 at 9:27
  • Have you tried setting the cache option to false? Easiest way is $.ajaxSetup({cache: false}); so that it's applied to all subsequent AJAX requests. You may also want to explicitly specify a data type of 'json' for that AJAX request (will also save you having to parse the response yourself). Commented Aug 29, 2012 at 9:29
  • Have a look at stackoverflow.com/questions/425854/… - it may be relevant Commented Aug 29, 2012 at 9:30
  • Also- check for malformed/unclosed tags in the document you are getting. All browsers but IE correct it. Instead, nothing happens- no errors or warnings-nothing!! Commented Dec 30, 2012 at 1:16

2 Answers 2

3

I was having this issue, but after a lot of trial and error I changed my php header code from...

header('Content-Type: application/json; charset=utf8');

to...

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

Solved it for me.

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

1 Comment

This also worked for me, but with Content-Type: application/json.
0

I'd build it with $.ajax as below, not sure if this is what you've already tried:

var dataToSend = {'name':'value', 'other':'bar'};
if($('input.something').attr('checked') == 'checked') {
   dataToSend.push({'more':'info'});
}
    $.ajax({
    url:'json_builder.php',
    data:dataToSend,
    success function(callback) {
       alert(callback);
        },
    dataType:'json'
    });

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.