Skip to main content

Bug Tracker

Side navigation

#7640 closed enhancement (worksforme)

Opened November 26, 2010 04:25PM UTC

Closed December 01, 2010 02:35PM UTC

Add load_send, load_complete, load_success and load_error event trigger on the core onload function

Reported by: Christophe KINNE <christophe@infra.fr> Owned by:
Priority: low Milestone: 1.5
Component: ajax Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:
Description

On some DOM elements I needed to use a generic function to show a "loading..." div in the element during the load operation and hide it when the load operation has finished.

As I have several different load operation I really needed a common way to trigger operations on the different states of the load action.

But if the global ajax event handlers .ajaxSend() and .ajaxComplete() are good for listeners, I was unable to use them for triggering a simple event on the element on which the load is done.

So i added 4 simple triggers at each step of the ajax request in the onload function. They work nicely I use them with .bind() and .live() without any problem.

I've seen some post on the forums of other people who wanted to do the same things so here is my (very) little patch for the 1.4.2 version, if you want to include it.

4819c4819
<               self.trigger('load_send');
---
> 
4827d4826
<                               self.trigger('load_complete');
4830d4828
<                                       self.trigger('load_success');
4845,4846c4843
<                               else { self.trigger('load_error'); }
< 
---
Attachments (0)
Change History (3)

Changed November 27, 2010 12:08AM UTC by jitter comment:1

component: unfiledajax
owner: → Christophe KINNE <christophe@infra.fr>
priority: undecidedlow
status: newpending

Thanks for taking the time to contribute to the jQuery project by suggesting an enhancement. I think the granularity of control available with the present ajax events is fine enough and would be hesitant to add more events (trade-off between speed and more control).

Maybe I just didn't fully understand what you intend to do, but can't you just use the existing ajax events and the context option to achieve what you describe? test case which shows how to reuse the same code for different DOM elements (does what I think you described).

Please report back if this example is able to handle the use cases you were thinking about. Or explain more in detail the possible use cases and how this example fails to solve them.

Changed December 01, 2010 02:35PM UTC by jitter comment:2

owner: Christophe KINNE <christophe@infra.fr>
status: pendingnew

Changed December 01, 2010 02:35PM UTC by jitter comment:3

resolution: → worksforme
status: newclosed