Hi Simon,

I'm not sure if you received a reply on this as I didn't see one but 
here's some sample code that may help:

$('#throbberSearch')
  .ajaxStart(function(){
   $("searchResultsDiv").hide();
   $(this).show();
     })
  .ajaxStop(function(){
   $(this).hide();
   $("searchResultsDiv").show();
     });

The methods ajaxStart() & ajaxStop() are built into jQuery and help you 
define actions when the Ajax calls are initiated and completed. They're 
a huge help for doing things such as loading a throbber/indicator and 
initializing some value.

$.ajax({type: "POST",
   url: "search.cfm",
   data: param + "&ms=" + new Date().getTime(),
   dataType: "html",
   success: function(msg){
        $("#searchResults" ).empty().append(msg);
            }
});     

For the success attribute, I tend to reference the div I'm updating by 
name. It just makes it much easier than trying to figure out its parent.

Give that a try.

Rey

SiCo wrote:
> Hi, I am trying to update a div with the response back from an ajax call, the
> trouble is I don't know what syntax to use or how to make it work properly.
> 
> $("[EMAIL PROTECTED]").click(function () {
> 
> // Firstly I grab the tags from the form I am replacing (upon clicking
> submit)
> var tags = $("[EMAIL PROTECTED]").val();
> 
> // Set the loading graphic
> $(this).parent().html(" \"ajax.gif\"  Saving...");
> 
> // Then make my ajax call
> $.ajax({
>             url: "ajax-updatetags.php",
>             type: "POST",
>             data: "tags=" + tags,
>             dataType: "html",
>             complete: function (){},
>             success: function (html) {
>                 $(this).parent().html(html);
>             },
>             error: function(){ alert("error") }
>         });
> 
> });
> 
> The line in my success function doesn't do anything
> $(this).parent().html(html); (the saving graphic just stays forever and
> ever!) I assume because parent is not related now we are in another
> function? How do I get back to my div and set the html. It needs to be the
> div we are in.
> 
> This all occurs in a $("div.tags").click(function() { as intially the div is
> converted to a form, then the form tags are taken, passed to the ajax and
> returned by the call upon success. Also how do I tell jQuery the request has
> failed from my PHP? Is there a special header or the like to return?? Or at
> least the page in the docs about this I haven't yet found anything on the
> specifics.
> 
> Thanks for any help.
> 
> Simon

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to