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! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---