I'm making a AJAX request with jquery like:
$.get('/Stuff.php', function (data) {
$('#own').html(data);
});
while this data is loading I want to display a small text at the top of the page (which just says "loading...") without blocking it.
how to do this?
What About jQuery and AJAX? jQuery provides several methods for AJAX functionality. With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!
AJAX is a developer's dream, because you can: Update a web page without reloading the page. Request data from a server - after the page has loaded. Receive data from a server - after the page has loaded.
jQuery ajax() MethodThe ajax() method is used to perform an AJAX (asynchronous HTTP) request. All jQuery AJAX methods use the ajax() method. This method is mostly used for requests where the other methods cannot be used.
Basically, ajax request as well as synchronous request sends your document cookies automatically.
use the ajaxSetup
$.ajaxSetup({
beforeSend:function(xmlHttpRequest){
//show the loading div here
},
complete:function(){
//remove the div here
}
});
now make the ajax call
$.get('/Stuff.php', function (data) {
$('#own').html(data);
});
$("#loading").show(); //before send
$.get('/Stuff.php', function (data) {
$('#own').html(data);
$("#loading").hide(); //when sucess
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With