3

The following code loads the page-handler.php into #page when the function load is fired and while waiting shows ajax_load. How can I make the ajax_load loding-message show in another div and of course disappear when the loding is finished?

function load(value) {
    $('#page').html(ajax_load);
    $("#page").load("page-handler.php", {page:value});
    return false;
}
1
  • wow everybody gave the same answer in less than a minute Commented May 19, 2011 at 15:18

5 Answers 5

2

You start by creating a hidden div with the loading message:

 <div id="loading">loading...</div>

Then in your function:

function load(value) {
    $('#loading').show();
    $('#page').html(ajax_load);
    $("#page").load("page-handler.php", {page:value}, function(){
            $('#loading').hide();
    });
    return false;
}

of course you have to do something about if the ajax call did not succeed.

Sign up to request clarification or add additional context in comments.

Comments

0
function load(value) {
    $('somediv').html(ajax_load);
    $("#page").load("page-handler.php", {page:value}, function() {
      $('somediv').empty(); // or set new contents, or hide, or whatever
    });
    return false;
}

This will put the contents into whatever has the id 'somediv'. You can use a class ('.class') or several other selectors to choose your div.

2 Comments

all type of solutions this far works, you were first with the solution I ended up using, thanks
@Joseph - look and Vincent's answer, please :)
0

Look into using $('#selector').ajaxStart() and $('#selector').ajaxStop();

http://api.jquery.com/ajaxStart/

Comments

0

Show a div before starting your call and hide it in a callback, e.g.:

function load(value) {
    $('#busydiv').show(); // shows busy indicator
    $('#page').html(ajax_load);
    $("#page").load("page-handler.php", {page:value}, function() {
         $('#busydiv').hide();
    });
    return false;
}

Comments

0

So I think this is what you want?

$("#anotherDiv").html(message);
$("#page").load("page-handler.php", {page:value}, function(){$("#anotherDiv").hide();});

That will hide the other div when ajax loads.

Comments

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.