Reputation: 11
I searched and it appears that I have the opposite problem to everyone else (They wonder why ajax returns null). I WANT my jquery/ajax function to return null if PHP echoes NULL but I get empty string instead. It's not a big deal but it's something that doesn't make sense for me now.
<script>
$.ajax({
url: "test.php",
success:function(result){
console.log(result);
}
});
</script>
<?php
echo NULL;
?>
//logs: empty string
I'll be embarased by the answer but I gotta know.
Thanks
Upvotes: 1
Views: 995
Reputation: 2610
Instead of echo NULL try returning an object that has a single property having value null
e.g.
obj
{
returnValue = NULL
}
I am not sure of PHP syntax but what i want to say is to wrap your return value in an object. and on client side you will get obj.returnValue as NULL instead of empty string
Upvotes: 1