Reputation: 5354
$.ajax({
url: "test.html",
context: document.body
}).done(function() {
//show data
});
how to save data from ajax request into a variable and then show it? and how to show a message "loading..." while it is proccessing?
Upvotes: 2
Views: 1049
Reputation: 22643
$.ajax({
url: "test.html",
context: document.body
}).done(function(data) {
alert(data);
});
UPDATED:
$.ajax({
url: "test.html",
context: document.body
}).done(function(data) {
$('#loading').hide();
// alert(data);
});
markup:
<div id='loading'></div>
Upvotes: 1
Reputation: 2069
You can try something like this. In your function you can show loading div
function your_ajax() {
$('#loading').show();
$.ajax({
url: "test.html",
context: document.body
}).done(function(data) {
$('#loading').hide();
alert(data);
});
}
Please add this part in your html
<div id="loading" style="display:none;">Loading </div>
Upvotes: 1
Reputation: 3778
For loading message, use beforeSend() in ajax.
beforeSend : function () {
$('body').html('Loading...');
}
Upvotes: 1