# Can RoR handle AJAX Response by Static Javascript code?

**URL:** <https://www.ruby-forum.com/t/can-ror-handle-ajax-response-by-static-javascript-code/189094>\
**Category:** Rails\
**Created:** [May 24, 2010, 2:33pm UTC](https://www.ruby-forum.com/t/can-ror-handle-ajax-response-by-static-javascript-code/189094 "2010-05-24T14:33:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [May 24, 2010, 2:33pm UTC](https://www.ruby-forum.com/t/can-ror-handle-ajax-response-by-static-javascript-code/189094/1 "2010-05-24T14:33:03Z")

</div>

So it looks like on RoR, when Ajax (using form\_remote\_tag) returns a  
success code, Javascript is also returned to handle the visual effects.

using Fiddler, I do see the following response:

```
try {
Element.update("vote_score", "Score 58");
$("vote_score").visualEffect("highlight");
} catch (e) { alert('RJS error:\n\n' + e.toString());

```

alert(‘Element.update(“vote\_score”, “Score  
58”);\n$(“vote\_score”).visualEffect(“highlight”);’); throw e }

Will there be situation where the code is quite big (like 1 or 2k) that  
RJS can use some sort of static Javascript already loaded to handle the  
effect?

Is there any other ways to use static Javascript already loaded with the  
page? Must it be just raw Javascript and use the Prototype’s Ajax  
success response to call the static Javascript code, or can it be some  
Rails mechanism related to RJS?

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [May 24, 2010, 2:51pm UTC](https://www.ruby-forum.com/t/can-ror-handle-ajax-response-by-static-javascript-code/189094/2 "2010-05-24T14:51:31Z")

</div>

Hi Jian L.,

On Mon, May 24, 2010 at 7:33 AM, Jian L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Will there be situation where the code is quite big (like 1 or 2k) that  
> RJS can use some sort of static Javascript already loaded to handle the  
> effect?

You can call any loaded Javascript function, including ones you’ve coded  
yourself, using page.call from an RJS template or render block. Cody  
Fauser’s “RJS Templates” PDF, available for $10 at O’Reilly, is still  
the  
best source on RJS IMHO.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![winterheat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7993a0/32.png) [@winterheat](https://www.ruby-forum.com/u/winterheat)\
**Post date:** [May 24, 2010, 3:09pm UTC](https://www.ruby-forum.com/t/can-ror-handle-ajax-response-by-static-javascript-code/189094/3 "2010-05-24T15:09:28Z")

</div>

Bill W. wrote:

> Hi Jian L.,
> 
> On Mon, May 24, 2010 at 7:33 AM, Jian L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Will there be situation where the code is quite big (like 1 or 2k) that  
> > RJS can use some sort of static Javascript already loaded to handle the  
> > effect?
> 
> You can call any loaded Javascript function, including ones you’ve coded  
> yourself, using page.call from an RJS template or render block. Cody  
> Fauser’s “RJS Templates” PDF, available for $10 at O’Reilly, is still  
> the  
> best source on RJS IMHO.

But why use RJS here, which tends to encourage poor-quality JavaScript  
programming? Heck, why use Rails and Ajax at all? If the JavaScript is  
static, just do the whole thing on the client side.

> HTH,  
> Bill

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
