Reputation: 36008
I know the following code would show a loading image when a button is clicked on the page:
$.ajaxSetup ({
cache: false
});
var ajax_load = "<img src='img/load.gif' alt='loading...' />";
var loadUrl = "ajax/load.php";
$("#load_basic").click(function(){
$("#result").html(ajax_load).load(loadUrl);
});
but what if I want this to happen soon as the page loads. I dont want the user interaction of clicking a button to make the ajax call.
Upvotes: 0
Views: 2878
Reputation: 550
You could try calling it from the $(document).ready() function. You might also want to check out this article, which adds a lot more to it.
Upvotes: 0
Reputation: 32137
jQuery(function(){
// now you are triggering click your self not waiting for uer to click,
//although he may click to start an ajax request
$("#load_basic").trigger('click');
});
Upvotes: 0
Reputation: 513
Throw it inside the document ready function:
$(document).ready(function() {
$.ajaxSetup ({
cache: false
});
var ajax_load = "<img src='img/load.gif' alt='loading...' />";
var loadUrl = "ajax/load.php";
$("#result").html(ajax_load).load(loadUrl);
}
Upvotes: 2