tags:

views:

186

answers:

3

My code works perfectly in FF, Safari and Chrome... just in IE 7 and 8 this happens...

My JQuery AJAX post looks like this:

$.post( 'page.php', { test: 'testing' }, function(r){
    alert('Data: ' + r);
});

Now, in IE, if the response (r) comes back blank, it will display the alert. However, if there is anything returned in the r (even if it's just a digit such a 1), it doesn't show the alert. No errors come up, it just doesn't show the callback...

Any ideas what might be wrong?

A: 

Did you try 'ticking' your test data key? Seems this happened to me once...

$.post( 'page.php', { 'test': 'testing' }, function(r){
    alert('Data: ' + r);
});
jeerose
A: 

If I were you, I would try explicitly telling jQuery what type of data you expect back. If you expect plain text, say so like this:

$.post( 'page.php', { test: 'testing' }, function(r){
    alert('Data: ' + r);
}, 'text' );

If you expect a JSON response, provide that:

$.post( 'page.php', { test: 'testing' }, function(r){
    alert('Data: ' + r);
}, 'json' );

You can read more about the acceptable types here.

Doug Neiner
Why the Downvote? Is there something wrong with the answer? Would love the opportunity to make it better.
Doug Neiner
+2  A: 

The "Internet Explorer" caches ajax-Request so first of all you should clear the cache of your browser and then edit your code to the following.

$.ajax({
      url: "page.php",
      type: "POST",
      cache: false,
      data: ({ test: 'testing' }),
      success: function(r){
          alert('Data: ' + r);
      }
   }
);

the use of cache: false forces the browser to not cache the result

Tim