Hi Josh,

It is not JQuery style. JQuery allows you to handle timeout event by
implementing error() callback like this

  jQuery.ajax({
    beforeSend: function(xhr) {
      // do something such as: set headers
    },
    type: "GET",
    timeout: 5000,
    url:
Pone.buildRestfulUrl(document.getElementById('ajaxCompanyLookup')),
    dataType: "json",
    success: function(response){
      jQuery('#loading').hide();
      handleJsonResponse(response);
      jQuery("#ajaxCompanyLookupButton").removeAttr('disabled');
    },
    error: displayError
  });

Now you can define a callback named displayError

function displayError(request, errorType, errorThrown) {
  try {
    if (errorType == 'timeout') {
      // do sonething here
    }
  catch (e) {}
}

More natural, right?

pcdinh
http://groups.google.com/group/phpvietnam

On Aug 21, 2:34 am, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:
> "timeout" is actually how long the request will wait to complete before it
> sends back atimeouterror.  You actually want setTimeout, like so.  This
> will wait five seconds before doing the ajax request.
>
> var t = setTimeout( function() {
>                $.ajax({
>                    type: "GET",
>                      url: "myurl.com",
>                    beforeSend: function() {
>                        $("#adminToolsListingA .scroll").html("");
>                       $("#adminToolsListingA .ajaxLoading").show();
>                   },
>                   success: function(html) {
>                        $("#adminToolsListingA .ajaxLoading").hide();
>                        $("#adminEditListingA .scroll").html(html);
>                     }
>                 });
>             }, 5000 );
>
> -- Josh
>
> ----- Original Message -----
> From: "hubbs" <[EMAIL PROTECTED]>
> To: "jQuery (English)" <jquery-en@googlegroups.com>
> Sent: Wednesday, August 20, 2008 11:25 AM
> Subject: [jQuery] $.ajax()timeout
>
> > I seem to not be understanding how the ajaxtimeoutworks, because it
> > does not seem to work how I thought.
>
> > I was hope it would delay the ajax request, for the number of
> > miliseconds that is specified, but that does not seem to be working.
> > Is thetimeoutused for something different?  Or is there a different
> > way to delay an ajax request for a few seconds?
>
> > Using:
>
> >                $.ajax({
> >                    type: "GET",
> >    timeout: 5000,
> >                    url: "myurl.com",
> >                    beforeSend: function() {
> >                        $("#adminToolsListingA .scroll").html("");
> >                        $("#adminToolsListingA .ajaxLoading").show();
> >                    },
> >                    success: function(html) {
> >                        $("#adminToolsListingA .ajaxLoading").hide();
> >                        $("#adminEditListingA .scroll").html(html);
> >                    }
> >                });

Reply via email to