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

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!
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 
For more options, visit this group at 

Reply via email to