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.

Aleks G
  • 56,435
  • 29
  • 168
  • 265
Matt
  • 1,139
  • 1
  • 11
  • 28
  • 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. – Aleks G Aug 29 '12 at 09:23
  • Yes I've tried using it without the shortcut, but to no avail.. – Matt Aug 29 '12 at 09: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). – Anthony Grist Aug 29 '12 at 09:29
  • Have a look at http://stackoverflow.com/questions/425854/jquery-ajax-request-failing-in-ie?rq=1 - it may be relevant – Aleks G Aug 29 '12 at 09: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!! – FredTheWebGuy Dec 30 '12 at 01:16

2 Answers2

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.

David Sherret
  • 101,669
  • 28
  • 188
  • 178
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'
    });
Liam
  • 27,717
  • 28
  • 128
  • 190