Reputation: 163
I want to display the #results
after the page load. But I don't know what events I should use. Any Help?
$(document).ready(function(){
//Live search
$("#search").on('keyup' ,function() {
//Input field value
var query = $(this).val();
$.post('search.php', { search: query}, function(cities) {
$('#results').stop(true,true).fadeIn(200).html(cities);
});//End ajax call
});//End on function
});//End document.ready state
Upvotes: 0
Views: 40
Reputation: 388446
You can load it in the document ready callback
$(document).ready(function () {
//this method loads the results based on the passed query
function load(query) {
$.post('search.php', {
search: query
}, function (cities) {
$('#results').stop(true, true).fadeIn(200).html(cities);
}); //End ajax call
}
//Live search
var $search = $("#search").on('keyup', function () {
//Input field value
load($(this).val());
}); //End on function
//on page load call the load method with the value in seach field
load($search.val());
}); //End document.ready state
Upvotes: 1