Reputation: 9865
I have a search function which executes on keyup
. The messages could be
displayRecords()
function.)I cannot seem to get the third scenario to work. My current code will shows "These are your search results..." and it will call the function to populate the table displayRecords()
if the user deletes the chars they have entered. How can I get the program to take all 3 of my scenarios into its logic.
$("#itemID").keyup(function (){
var url = searchPath;
$.ajax({
type : "POST",
async : false,
url : url,
data: $('#itemID').serialize(),
cache : false,
success: function(html) {
$( "#productResults" ).html( html );
if (html === null) {
$("#loader_message").html('<p>There were no results that match your search criteria</p>').show();
} else {
$("#loader_message").html('These are your search results... <img src="../wp-content/uploads/2016/02/loading.gif" alt="Loading">').show();
}
if( !$('#itemID').val() ) {
displayRecords(limit, offset);
}
html = null;
window.busy = false;
}
});
});
Upvotes: 0
Views: 51
Reputation: 100175
probably your variable html is not null, using jQuery.trim() to remove extra whitespaces from your response data, so that you can check for emptiness, as
..
if ($.trim(html) === '') { //check if its blank
$("#loader_message").html('<p>There were no results that match your search criteria</p>').show();
} else {
$("#loader_message").html('These are your search results... <img src="../wp-content/uploads/2016/02/loading.gif" alt="Loading">').show();
}
..
Upvotes: 1