I have a search function which executes on keyup
. The messages could be
- Shows loading when there are results
- Reloads full table when user deletes values or does not add any chars to the search field. (This scenario recalls on the
displayRecords()
function.) - Tells the user there are no results.
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;
}
});
});