$("#Submit").click(function(event){
event.preventDefault();
var th = '<tr><th>' + "Business" +'</th><th>' + "Address"+ '</th><th>'+ "Rating" + '</th><th>' + "Date" + '</th></tr>';
$("#restaurants").empty().html(th);
var Searching = $("#Search").val();
$.ajax({
type : "GET",
url : "http://www.cs.kent.ac.uk/people/staff/lb514/hygiene/hygiene.php",
dataType : "json",
data : {op : "searchname", name : Searching},
success : function(data){
$.each(data,function(key,results){
if(results.length > 1){
$("#restaurants").append(
"<tr><td>" + results.business +"</td>"+
"<td>" + results.address + "</td>" +
"<td>" + results.rating + "</td>" +
"<td>" + results.date + "</td></tr>"
)
}else if( results.length < 1){
alert("The search term ");
}
})
}
});
})
This is an AJAX request, called after the user press the submit button to search for a restaurant. Now for a better design I included if
statement to check whether the callback object is empty but it doesnt work.
However, even with this I have tested and it works if you give a similar name to a restaurant. But it doesnt alert if you give a name that is not in the database and I don't see where I went wrong.
PS. I also tried data.length