Maybe I'm missing something obvious... but if the timing of onCreate
is sufficient, why not just execute the specific code immediately
before creating the new request?
i.e.
doSomethingImportant();
new Ajax.Request(...);
TAG
On Jun 4, 2007, at 4:32 PM, Rich wrote:
>
> Hi Tom,
>
> Thanks for your response. I did see this responder stuff in the
> documentation, but didn't realise it was the workaround per se, so
> thanks for the heads up.
>
> I've been trying to get them to work for the last hour or so and I'm
> running into a perhaps obvious problem.
>
> I need the responder to be local to a request, and not global. I
> thought I could get around this by registering the responder,
> initialising the Ajax.Request, and then unregistering the responder -
> in that order. This seems to be half working, but... perhaps I'm
> unclear just exactly what "onComplete" is.
>
> Here is my code:
>
> Responder:
>
> var ajaxResponder = new Ajax.Responders.register({
> onCreate: alert('Created'),
> onComplete: alert('Completed')});
>
> Request:
>
> new Ajax.Request('ajax/pagecontent.php', {
> method: 'get',
> parameters: {pageid: id, time: Math.random()}
> });
>
> Unregister responder:
> Ajax.Responders.unregister(ajaxResponder);
>
>
> Now, at the top of pagecontent I have a PHP sleep() statement which
> should halt the page for 5 seconds. By doing this, I am hoping that I
> see an alert box that says "Created" and then another alert box
> followed 5 seconds later with "Completed". Instead I am seeing
> immediate consecutive alert boxes.
>
> As this is the case, I assume that onComplete only referes to the
> actual AJAX request completing, and not the return of data? If so, is
> there a way I can actually have it alert once fully complete and data
> has been returned?
>
> Cheers,
> Rich.
>
>
>
>
>
>
>
> On Jun 4, 9:38 pm, Tom Gregory <[EMAIL PROTECTED]> wrote:
>> It is in the documentation [1], and has been brought up on this list
>> recently [2]. Search the archives [3].
>>
>> "Depending on how your browser implements XMLHttpRequest, one or more
>> callbacks may never be invoked. In particular, onLoaded and
>> onInteractive are not a 100% safe bet so far. However, the global
>> onCreate, onUninitialized and the two final steps are very much
>> guaranteed."
>>
>> The short version: it depends on your browser.
>>
>> Perhaps those who manage the docs should style the paragraph to
>> provide a stronger visual warning.
>>
>> 1.http://prototypejs.org/api/ajax/request
>> 2.http://groups.google.com/group/rubyonrails-spinoffs/browse_frm/
>> thread/3a57ad6d644a28fe/c7bf329b539d8edf?
>> lnk=gst&q=onloading&rnum=3&hl=en#c7bf329b539d8edf
>> 3.http://groups.google.com/group/rubyonrails-spinoffs/search?
>> hl=en&group=rubyonrails-spinoffs&q=onloading&qt_g=Search+this+group
>>
>> TAG
>>
>> On Jun 4, 2007, at 2:27 PM, Rich wrote:
>>
>>
>>
>>
>>
>>
>>
>>> Hi there,
>>
>>> Firstly, I apologise if this is hidden somewhere in the
>>> documentation,
>>> but I assure you I've read through it all and couldn't see anything
>>> relating to this. I am new to prototype, and am slowing getting to
>>> grips with it (and JS in general).
>>
>>> Today I had a user report to me that they are seeing the results of
>>> the OnLoading event handler *after* the OnComplete.
>>
>>> By this, what I mean is that I simply have a textarea field on a
>>> page,
>>> of which the contents are pulled using a prototype GET request.
>>> They
>>> see "Loading..." as I have specified from the OnLoading handler.
>>> They
>>> then see the relevant text in the textarea, and then it seems to
>>> somehow go back to OnLoading extremely quickly, all in a flash.
>>> Either that, or for some reason OnLoading is kicking in *after*
>>> OnComplete has finished.
>>
>>> I have only managed to reproduce this once, and now I can't :/
>>
>>> Is there any particular order in which you are meant to specify
>>> OnEvent handlers? Should OnComplete come BEFORE OnLoading?
>>> Anyone
>>> have any ideas what the problem may be?
>>
>>> Thanks in advance,
>>> Rich.
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---