> From: barophobia
> 
> I'm trying to delay the appearance of $.ajaxStart() using 
> setTimeout() but I've been unable to get it to work.
> 
> I've used it once before in something else and I'm basically 
> just trying to copy that for $.ajaxStart().
> 
> http://www.pastebin.ca/678318
> 
> When I run that code I get "t has no properties, 
> jquery-1.1.4-compressed.js line 11".
> 
> How do I do this properly?

Inside your setTimeout callback function, "this" is not what you expect.

Add "var element = this;" before the setTimeout, and then use "$(element)"
instead of "$(this)" inside the function.

Also, it looks like you have a race condition. What happens if the entire
AJAX request completes in less than 100 milliseconds?

I posted some untested code that should fix both of these:

http://www.pastebin.ca/678388

> On a related note, what would be really great is a delay option for
> $.ajaxStart() itself. My goal is simply to delay the 
> appearance of the "Loading..." div until the ajax calls runs 
> beyond a set time limit.

Excellent idea!

-Mike

Reply via email to