views:

49

answers:

2

Hi, I have an IE problem. I am using the jquery ajax method to call a php script. The php script just calls die(). In firefox, the error message is displayed, but in IE the success message is displayed without any data. I would prefer the error function to be called.

Is there any way to fix this? I'm guessing my javascript code needs change somehow.

Thanks!

<?php
    die()
?>

$.ajax({
    url: "phps/php.php?id="+the_id,
    dataType: "json",
    error: function(){
        alert('error');
    },
    success: function(data){
        alert("SUCCESS");
    }
});
A: 

I guess Firefox and the other browsers do consider an empty call an error, but IE does not, try this in your PHP script if you want to cause all of them to err:

header("HTTP/1.0 400 Bad Request");

From wikipedia:

400 Bad Request The request contains bad syntax or cannot be fulfilled

Francisco Soto
THANKS! (very much)
BizMark
A: 

error(XMLHttpRequest, textStatus, errorThrown)
A function to be called if the request fails. The function is passed three arguments: The XMLHttpRequest object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "notmodified" and "parsererror".


success(data, textStatus, XMLHttpRequest)
A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the 'dataType' parameter; a string describing the status; and the XMLHttpRequest object (available as of jQuery 1.4).

source

ajax() and php combination. try reading this.

Reigel