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

M1X
  • 4,971
  • 10
  • 61
  • 123

3 Answers3

1
 $.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>
Gildas.Tambo
  • 22,173
  • 7
  • 50
  • 78
1

For loading message, use beforeSend() in ajax.

  beforeSend : function () {
      $('body').html('Loading...');
  }
Rajesh
  • 3,743
  • 1
  • 24
  • 31
1

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>
Shafeeque
  • 2,039
  • 2
  • 13
  • 28