Hello,
Why not do exactly what you say, compose all the parameters for the request
and execute whenever you want:
var url = '/foo.php';
var ajaxOptions = {
option1: foo,
option2: bar
}
// do whatever you want..
// even add something
ajaxOptions.option3 = 'bla';
// then execute
new Ajax.Request(url, ajaxOptions); // uses the ajaxOptions
Or did I not fully understand what you wanted?
Greetings,
Johan
On Tue, Aug 31, 2010 at 3:29 PM, Richard Quadling <[email protected]>wrote:
> Hi.
>
> Imagine a component which has a method which allows a third party to
> supply some data after the initial creation of the component using
> "new".
>
> e.g.
>
> // Initial creation.
> var myComp = new MagicComp({option1:value1, option2:value2});
>
> // Some time later, maybe as a result of a click event.
> myComp.setItems({item1:value1, item2:value2});
>
> sort of thing.
>
>
>
> Now, a common pattern would be to use an Ajax.Request to get the data.
>
>
> I would like to have the ability to pass the ajax request as part of
> the initial creation, but to not have the request actually actioned
> until some time later.
>
> Does the creation of an Ajax.Request force the execution of the
> request in all circumstances.
>
> I suppose all I'm really interested in is the URL of the request, but
> I'd like to allow third parties more control over this if necessary.
>
> // Initial creation.
> var myCompAjaxed = new MagicCompAjaxed({option1:value1, ajax:new
> AjaxRequestButNotYetActive()})
>
>
> Ultimately, I'm trying to delay the request and processing within the
> component until it is actually needed. And so I want to be able to
> define all the information (params, callbacks, etc.) for the
> Ajax.Request, but just not have it run until needed (just-in-time).
>
> It would look like that my best option is something like ...
>
> // Initial creation.
> var myCompAjaxed = new MagicCompAjaxed({
> option1:value1,
> AjaxRequestURL : '....';
> AjaxRequestOptions : {...}
> });
>
> and have ...
>
> MagicCompAjaxed.doTheWork : function(){ new
> Ajax.Request(this.AjaxRequestURL, this.AjaxRequestOptions)}
>
> sort of thing.
>
> But then how do I extract the data from the request (onSuccess()) but
> still allow the end user to have an onSuccess option?
>
> Argh.
>
> Inheritence is the answer here ... just getting a little lost...
>
> Or going down the wrong track entirely!
>
>
>
>
> Any ideas/suggestions/examples/etc.
>
> Regards,
>
> Richard Quadling.
>
> --
> 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]<prototype-scriptaculous%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
>
--
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.