1

I'm using jquery to make an AJAX call that returns an HTTP 500 error. Works fine in firefox, but IE reports a 200 error. I know the PHP is right, because if I go to the page directly, it shows up as a 500 error. It's just the jQuery part that doesn't work in IE.

Here's the ajax call:

$.ajax({
  url: "download.php",
  data: {
    removefile: filename
  },
  type: "GET",
  dataType: "html",
  success: function(html) {
    alert("Success");
  },
  error: function(xhr, status, errorThrown) {
    alert("Error: " + xhr.status);
  },
  complete: function(xhr, status) {
    alert("Complete: " + xhr.status);
  }
});

The php I'm using is something like:

header($_SERVER['SERVER_PROTOCOL'] . " 500 Internal Server Error", true, 500);
echo "Remove failed";

I'm testing on IE 9, but tried all of the different compatibility modes with the same issue.

Any ideas?

deuberger
  • 3,578
  • 6
  • 31
  • 33

1 Answers1

1

Duh! Changing the request type from "GET" to "POST" solves the problem. Guessing IE was caching the response. Not the same question, but Error with Internet Explorer and Jquery Ajax has a similar answer.

Sorry for the noise.

Community
  • 1
  • 1
deuberger
  • 3,578
  • 6
  • 31
  • 33
  • Quick tip: you can disable caching - `cache:false` – Jack Jul 23 '14 at 20:41
  • @JackWilliam: thanks for the tip. Would that be recommended though? From what I'm reading at http://learn.jquery.com/ajax/key-concepts/, it sounds like the de facto route should be to use POST and that there is no need to cache then? – deuberger Jul 24 '14 at 12:15
  • No problem :-) Yeah, I would in some cases, But it definitely depends on your data and the application, for instance if your handling passwords or sensitive data you shouldn't be using GET, period. It is, however, worth noting that GET is slightly faster, [learn more here](http://stackoverflow.com/questions/1211881/why-get-method-is-faster-than-post) – Jack Jul 24 '14 at 15:22