As you can see I am retrieving JSON data from my ajax call but if the database can’t find anything it returns the print value of null.
e.g.
print "null";
as you can see with case 1 I have asked it if it can not find obj.id then show this.
However as there is NO JSON being returned it should be if(data == "null") however it seems to work when I do that either.
I basically need it to notice that it could not find it, and to stop the script.
here is my jquery code.
function fetch(e,formstring)
{
$.ajax({
type: 'POST',
url: 'system/classes/core.php',
data: formstring,
dataType: 'json',
contentType: "application/x-www-form-urlencoded;charset=utf-8",
success: function(data){
$.each(data, function(i, obj) {
switch (e) {
case 1:
if(!obj.id)
{
shownotify(1,"Sorry An error was found. Check Username / Password.");
alert("error");
shownotify(2,"");
return false;
}
$.each(obj, function(key, val) {
alert(key+" - "+val);
});
break;
case 2:
$.each(obj, function(key, val) {
if(val != 0)
{
$("#betataken").html("<span style='color:red'><b>"+betacode+"</b> - NOT VALID");
}
else
{
$("#betataken").html('<img src="theme/sysimages/tick.png"/><span style=" color: white;"><b>'+betacode+'</b> is valid</span');
}
});
break;
case 3:
$.each(obj, function(key, val) {
if(val != 0)
{
$("#usernametaken").html("<span style='color:red'><b>"+username+"</b> - is taken");
}
else
{
$("#usernametaken").html('<img src="theme/sysimages/tick.png"/><span style=" color: white;"><b>'+username+'</b> is valid</span');
}
unamecheck = val;
});
break;
case 4:
//LoginSript
$('#rightheader').html(obj.code);
break;
case 5:
//WelcomePage/Signup
$('#window').html(obj.code);
break;
}
});
},
error: function(data){
$.each(data,function(i,myinfo){
alert(i);
});
},
complete: function(){
shownotify(2,"");
}
});
return false;
}
You could return null as json (
$return['result'] = 'null';in the php-file).In your js: