Some problems with AJAX / JQuery. Here is the context of my problem, followed by a sample code:
What I'm trying to do is call a PHP script called getInfo.php and check if any data is contained in the database. I can write queries quite easily, but from the point of view of the code example below, how can I “say” that the success function fails if it cannot find the data in the database and instead run the error function?
$(document).ready(function(){
getInfo();
function getInfo(){
$.ajax({
type: "GET",
url: "getInfo.php",
data: "do=getInfo",
cache: false,
async: false,
success: function(result) {
$("#myInfo").remove();
alert("Data found");
},
error: function(result) {
alert("Data not found");
}
});
}
});
Any advice would be greatly appreciated. =)
source
share