[jQuery] Re: Creating an ajax status

2009-04-16 Thread Jordon Bedwell

$.ajax supports an option called beforeSend so it would be something like:

$.ajax({
type:POST,
url:some.php,
data:name=Johnlocation=Boston,
success:function(msg){
alert(Data Saved: +msg);
}
beforeSend:function() {
alert(Sending request to server');
}
 });

I am assuming you are using $.ajax because you are probably using the same
page with either GET or POST.

-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of Nic Hubbard
Sent: Thursday, April 16, 2009 11:31 AM
To: jQuery (English)
Subject: [jQuery] Creating an ajax status


I have a number of GET and POST ajax calls that do various things my
script.  For each one, I would like to set a status that is a string,
so that I can out put that to the user.  So, it might look like this:

Ajax POST
Posting to page

Ajax GET
Getting content page

Ajax POST
Sending data to page

Basically I want to set the status using something like $
('#status_div').text(); so that the user will see the status text when
each ajax function is run.

Does anyone have ideas on how this could be accomplished?



[jQuery] Re: Creating an ajax status

2009-04-16 Thread Donny Kurnia

Nic Hubbard wrote:
 I have a number of GET and POST ajax calls that do various things my
 script.  For each one, I would like to set a status that is a string,
 so that I can out put that to the user.  So, it might look like this:
 
 Ajax POST
 Posting to page
 
 Ajax GET
 Getting content page
 
 Ajax POST
 Sending data to page
 
 Basically I want to set the status using something like $
 ('#status_div').text(); so that the user will see the status text when
 each ajax function is run.
 
 Does anyone have ideas on how this could be accomplished?
 

This is what I used to do:

1. In the click function handler, put the loading text and image to the
status placeholder.
$('#status_div').html('img src=loading.gif / Loading ...');

2. Call the ajax

3. In the ajax callbak function, I update the status placeholder with
the ajax response message
$.post(url
   ,{param: value}
   ,function(r){
 $('#status_div').html(r.message);
   }
   , json);

The complete code will be like this:
$(trigger).click(function(){
  $('#status_div').html('img src=loading.gif / Loading ...');
  $.post(url
 ,{param: value}
 ,function(r){
   $('#status_div').html(r.message);
 }
 , json);
});

You can adjust this according to your need. This is what I like to do in
my code (and my client so far happy with it) :)

--
Donny Kurnia
http://hantulab.blogspot.com
http://www.plurk.com/user/donnykurnia



[jQuery] Re: Creating an ajax status

2009-04-16 Thread Nic Hubbard

I got this working, thanks guys.

On Apr 16, 10:19 am, Donny Kurnia donnykur...@gmail.com wrote:
 Nic Hubbard wrote:
  I have a number of GET and POST ajax calls that do various things my
  script.  For each one, I would like to set a status that is a string,
  so that I can out put that to the user.  So, it might look like this:

  Ajax POST
  Posting to page

  Ajax GET
  Getting content page

  Ajax POST
  Sending data to page

  Basically I want to set the status using something like $
  ('#status_div').text(); so that the user will see the status text when
  each ajax function is run.

  Does anyone have ideas on how this could be accomplished?

 This is what I used to do:

 1. In the click function handler, put the loading text and image to the
 status placeholder.
 $('#status_div').html('img src=loading.gif / Loading ...');

 2. Call the ajax

 3. In the ajax callbak function, I update the status placeholder with
 the ajax response message
 $.post(url
        ,{param: value}
        ,function(r){
          $('#status_div').html(r.message);
        }
        , json);

 The complete code will be like this:
 $(trigger).click(function(){
   $('#status_div').html('img src=loading.gif / Loading ...');
   $.post(url
          ,{param: value}
          ,function(r){
            $('#status_div').html(r.message);
          }
          , json);

 });

 You can adjust this according to your need. This is what I like to do in
 my code (and my client so far happy with it) :)

 --
 Donny Kurniahttp://hantulab.blogspot.comhttp://www.plurk.com/user/donnykurnia