Jump to content

[SOLVED] jQuery / AJAX - How to show Ajax request status using a loading image...


suttercain

Recommended Posts

Hi everyone,

 

I am a newbie in jquery and have been stuck on this all morning. I am using the following function to perform an AJAX request which loads in the specified DIV:

 

function showUser(str)
{
  $('#content1').load("select.php?q="+str);
}

 

This works fine but I tried to add a loading gif (you know those nice circles) and I got it kind of working. The gif would show up and go away when the content was loaded but I had two problems. The image would show up on first load and just sit there until the user clicked a link for the AJAX request and the second error was the image would appear above the paragraph and not make the content go away until the new request was completed.

 

Can someone show a simple call to include the loading image so it's only displayed while the content is being fetched?

 

I tried this with no success:

 

$().ajaxSend(function(r,s){
        $("#content1").load("Loading data, please wait...");
   });

 

Thanks.

 

PS. I tried posting this over at jQuery.com but got an error message.

Link to comment
Share on other sites

function showUser(str)
{
  //Set the contents to a loading message
  $('#content1').html('Loading data, please wait...');
  //Make the AJAX Call
  $('#content1').load("select.php?q="+str);
}

..and, since jQuery is awesome, you should be able to stack them into one command:

function showUser(str)
{
  $('#content1').html('Loading data, please wait...').load("select.php?q="+str);
}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.