Wednesday 17 January 2018

php - How to check if ajax return exist?





I have an ajax
request:



$.ajax({
url:
'DBConnector.php',
type: 'GET',
dataType:
'json',

success: function(data){
//check if
exist
}
});


This
is what i return:



echo
json_encode(array("data" => $returnValue , "status" =>
"false"));



How
to check if status exist(not to be false but really if it
exist)?



Answer




You can try the
following:



$.ajax({

url: 'DBConnector.php',
type: 'GET',
dataType: 'json',

success: function(data)

{
if(data.status !==
undefined)
{
//YOUR CODE HERE
}

}
});


It
will check if the status exists or
not.



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...