Reputation: 41
i have been table site for some time now and i implemented a searching system, but i want it to be real time search so whenever you press a button it will refresh the site. I have little coding experiance so ill ask for some help here.
Here is my ajax code:
function searchDomains() {
$.ajax({
type: "POST",
url: "Ajax/searchDomain.action.php",
data: {
domain: $('input[name="domain"]').val(),
width: $(window).width()
},
success: function(data) {
$("#container_domains").html(data);
}
});
}
Upvotes: 0
Views: 1581
Reputation: 167172
You are almost right, but you need to attach this function to the keyup
event of the <input />
and make it unobtrusive too:
<input type="text" name="search" id="search" />
<div id="container_domains"></div>
And in the jQuery:
$(function () {
$("#search").keyup(function () {
$.ajax({
type: "POST",
url: "Ajax/searchDomain.action.php",
data: {
domain: $('input[name="domain"]').val(),
width: $(window).width()
},
success: function(data) {
$("#container_domains").html(data).show();
}
});
});
});
Upvotes: 1