awesome! :) ill get on it right away. thanks!

On Thu, Jan 8, 2009 at 4:33 PM, T.J. Crowder <t...@crowdersoftware.com> wrote:

>
> Hi Ram,
>
> > thanks a lot for your reply!
> > you're telling me that since, in this case, im using the Ajax response
> > immediately to update div elements, it needs to be synchronous..
> > right?
>
> No, I wouldn't do that.  What I would do is make the call asynchronous
> and handle the success/failure of it with the callbacks provided.
> Making Ajax calls synchronously freezes the UI of the browser until
> the call completes, and so makes for an unpleasant user experience.
>
> > i removed the 'new' operator. But...
>
> You don't want to remove it.  You want to create a new Ajax.Request
> because that's how Ajax.Request is used.  I'm just saying that:
>
>    var tax_1 = new Ajax.Request(...)
>
> sets tax_l to be the new Ajax.Request object, and so passing it into
> Element#update is not going to do what you want.
>
> Again, have a good solid read through the API docs and things will be
> a lot clearer.  Also, here's an article I wrote for the unofficial
> Prototype & script.aculo.us wiki which should help:
> http://proto-scripty.wikidot.com/prototype:how-to-bulletproof-ajax-requests
>
> > What I
> > meant to ask was, is there a way to return the whole object and then
> > access its individual attributes?
>
> Sure.  What I'd do in that situation is have the server-side request
> return the object's properties in JSON[1][2] format (being sure to set
> the content type to "application/json"), and then I'd access those
> through the responseJSON property of the transport parameter in the
> onSuccess handler.  As it happens, the article I linked above does
> exactly that, so it should get you going.
>
> [1] http://json.org
> [2] http://en.wikipedia.org/wiki/JSON
>
> HTH,
> --
> T.J. Crowder
> tj / crowder software / com
>
>
> On Jan 8, 4:08 am, Ram <yourstruly.vi...@gmail.com> wrote:
> > Hi T.J.Crowder,
> >
> > thanks a lot for your reply!
> > you're telling me that since, in this case, im using the Ajax response
> > immediately to update div elements, it needs to be synchronous..
> > right? ill do that.
> > i removed the 'new' operator. But Firebug throws this error
> > "this.initialize is undefined" (line 48)
> > var Class = {
> > 42 create: function() {
> > 43 var parent = null, properties = $A(arguments);
> > 44 if (Object.isFunction(properties[0]))
> > 45 parent = properties.shift();
> > 46
> > 47 function klass() {
> > 48 this.initialize.apply(this, arguments);
> > 49 }
> > Any idea what might be breaking it?
> >
> > Also, I dint mean to ask how I can manipulate the object i create.
> > Basically, when I query for the tax in the controller with its id, i
> > intend to use many of its attributes (those stored in the db like
> > name, reference symbol, etc) to update divs all around the page. But
> > right now, im returning just the name from the controller. What I
> > meant to ask was, is there a way to return the whole object and then
> > access its individual attributes?
> > And yes, Im reading the docs :). Thanks again..
> >
> > On Jan 7, 5:27 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> >
> > > Hi Ram,
> >
> > > The "new" operator creates a new object.  You're assigning that object
> > > to the variable tax_1, and then passing that into Element#update.
> > > That's why you're getting [object] in your output.
> >
> > > Most times, you don't need to use the object you're creating.  To
> > > manipulate the results of a request, you want to use the various
> > > callbacks (usually onSuccess, onFailure, and onException) provided by
> > > the request.  See the Ajax options[1] for details.
> >
> > > Note also that you've explicitly said "asynchronous: true" in your
> > > request (which isn't actually necessary; that's the default).  So your
> > > request is not happening inline with the code where it's initiated
> > > (e.g., not happening synchronously), it's happening *a*synchronously.
> >
> > > If you have a good thorough read through the various Ajax objects in
> > > the API documentation, you should start to get an idea how this stuff
> > > works.  There are also some examples and discussion on the unofficial
> > > Prototype & script.aculo.us wiki[2].
> >
> > > [1]http://www.prototypejs.org/api/ajax/options
> > > [2]http://proto-scripty.wikidot.com
> >
> > > HTH,
> > > --
> > > T.J. Crowder
> > > tj / crowder software / com
> >
> > > On Jan 7, 11:35 am, Ram <yourstruly.vi...@gmail.com> wrote:
> >
> > > > Hi,
> >
> > > > Im making an Ajax get request in my Rails application.
> >
> > > > This is the JS code.
> > > > function taxes() {
> > > >         var id_1 = $('tax_1').value;
> > > >         var url = '/taxes/tax_name/'+encodeURIComponent(id_1);
> > > >         var tax_1 = new Ajax.Request(url, {
> > > >             asynchronous: true, evalScripts: true,
> > > >             method: 'get'
> > > >           });
> > > >         name_1 = tax_1;
> > > >         $('tax_1_name').update(name_1);
> >
> > > > }
> >
> > > > And this is the controller code for the requested action.
> > > > def tax_name
> > > >     tax = Tax.find(params[:id])
> > > >     return tax.name
> > > > end
> >
> > > > Fairly simple. But the output in the 'tax_1_name' div says "[object
> > > > Object]". Thats all. I guess that means the request is returning an
> > > > object. But how do i display the value correctly?
> > > > And ideally, I would like the request to return the tax (and not the
> > > > tax.name), and then use the returned ActiveRecord object in updating
> > > > various divs with various attributes of this returned object. How can
> > > > i do that?
> > > > Im new to prototype and hoping to play with all its goodies over the
> > > > next few weeks :D. Hope to find guidance here. Thanks!
> >
> >
> >
>


-- 
In Sport We Trust !!!

--~--~---------~--~----~------------~-------~--~----~
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 prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to