Jeztah wrote:
> Morning guys/gals.
>
> I have some weird behaviour regarding Event.stop();
>
> $$('.quickdetails').invoke('observe','click',function(event) {
>
>
> var this_href=$(this).readAttribute('href');
> var element=this;
> var arr=this_href.split("/");
> if(arr.length<3) { return; }
> var vacancy_id=arr[arr.length-1];
>
> window.eEvent=event;
>
> var request=new Ajax.Request('/VacancyInfo',{
> evalScripts: true,
> method: 'get',
> parameters:
> {
> id:vacancy_id
> },
> onSuccess : function(transport) {
>
>
> var text=transport.responseText;
>
>
> $modals.showVacancy({string:text,node:element});
>
> Event.stop(window.eEvent); // doesnt stop it
> Event.stop(event); // doesnt also stop
> the event
> },
> onError : function() {
> return true;
> }
> });
> request=null;
> //Event.stop(event); // stops it
> });
> });
>
> ............
>
> Would it be better to set a variable in the "onSuccess" and then query
> the variable after the Ajax.Request ? as calling Event.stop() inside
> the handler does not seem to work on any browser ?
>
> Regards
> Alex
"After the AJAX request", in terms of lines of code, is not the same as
it is in terms of execution time. In fact, if you'd put the
Event.stop() after the Ajax.Request instantiation, it would get executed
earlier than then onSuccess handler function (which is executed
asynchronously).
So, what goes wrong in the case given is that the Event.stop(event) (in
the onSuccess handler) is called later, when the event has spent its
whole lifetime (and has triggered any other handlers observing on
elements above the clicked quickdetails element, as well as the default
action).
This is a tricky case. If you really must stick with the click event
(e. g. there might be some other handlers that are not under your
control), I'd suggest to stop() the original event in any case, so no
further handlers are triggered. Then, if the AJAX call should fail,
clone the event and re-issue it. (I gather Element.fire() doesn't help
you with that, so some browser-dependent magic would have to be worked.)
Otherwise, if you're only interested in switching to the href URL of the
clicked link, it's probably easiest to set window.location.href in the
AJAX call's onError handler.
Hope that's useful
----Daniel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---