M1X
M1X

Reputation: 5354

how to save ajax call request data in a variable and show it?

$.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

Answers (3)

Gildas.Tambo
Gildas.Tambo

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

Shafeeque
Shafeeque

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

Rajesh
Rajesh

Reputation: 3778

For loading message, use beforeSend() in ajax.

  beforeSend : function () {
      $('body').html('Loading...');
  }

Upvotes: 1

Related Questions