JQuery ajax and php die ()

I have a problem with IE. I am using jquery ajax method to call php script. The PHP script just calls die (). In firefox, it shows an error message, but in IE, it shows the success message without any data. I would rather call the error function.

Is there a way to fix this? I am guessing my javascript code needs to be changed somehow.

Thanks!

<?php
    die()
?>

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

      

+2


a source to share


2 answers


I think Firefox and other browsers consider the empty call to be an error, but IE doesn't, try this on your PHP script if you want all of them to be wrong:

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

      



From Wikipedia:

400 Bad Request The request contains bad syntax or cannot be completed.

0


a source


error (XMLHttpRequest, textStatus, errorThrown)
Function to be called if the request fails. The function has three arguments: An XMLHttpRequest object, a string describing the type of error that occurred and the optional exception object if it occurred. Possible values ​​for the second argument (other than zero) are timeout, error, notmodified, and parsererror.


success (data, textStatus, XMLHttpRequest)
. Function if the request is completed successfully. the function takes three arguments: Data returned from the server, formatted according to the 'dataType' parameter; a line describing the state of affairs; and an XMLHttpRequest object (available in jQuery 1.4).



a source

ajax()

and a combination of php. try reading this .

0


a source







All Articles