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?

2

3 Answers 3

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>
Sign up to request clarification or add additional context in comments.

1 Comment

thanks how to show a "loading..." message when a request is send ?
1

For loading message, use beforeSend() in ajax.

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

Comments

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>

1 Comment

how to wrap this in a timeout request for example refresh every 5 sec?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.