Here am sending contents of the textbox with class searcher using keyup event by ajax. I wanted not to send ajax request if the textbox with class searcher is empty and clear the content of a div with id sub_cont. but i couldn’t do it.
anyone help with pointing out where am wrong
thanks
$(".searcher").keyup(function(){
if($('.searcher').val == "")
{
$('#sub_cont').fadeOut(1500);
}
else{
//show the loading bar
showLoader();
$('#sub_cont').fadeIn(1500);
$("#content #sub_cont").load("main/search.php?val=" + $("#search").val(), hideLoader());
}
});
You should use
$.getinstead of$.fn.loadhere for several reasons:abort()the previous ajax request before sending a new one.loadgives you no escape hatch if there is an error whereasgetdoes.$.getyou’ll learn a lot more about jQuery and javascript. :-p