# How to execute remote action once as the page loads?

**URL:** <https://www.ruby-forum.com/t/how-to-execute-remote-action-once-as-the-page-loads/118548>\
**Category:** Rails\
**Created:** [October 28, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/how-to-execute-remote-action-once-as-the-page-loads/118548 "2007-10-28T17:24:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cvandyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f6c823/32.png) [@cvandyck](https://www.ruby-forum.com/u/cvandyck)\
**Post date:** [October 28, 2007, 5:24pm UTC](https://www.ruby-forum.com/t/how-to-execute-remote-action-once-as-the-page-loads/118548/1 "2007-10-28T17:24:42Z")

</div>

Hello

One of my application pages needs to grab data from two different XMLRPC  
endpoints – it’s kind of expensive sometimes. So I decided to load  
that information using two separate ajax requests as the page loads.

In the view, it looks like this:

 \<%= image\_tag "spinner.gif "%\> \<%= javascript\_tag "var jira\_loaded = false"%\> \<%= periodically\_call\_remote ( :update=\> "jira\_information", :frequency=\>0, :url=\>{:controller=\>:person, :action=\>:fetch\_ajax\_jira, :id=\>@person}, :condition =\> "jira\_loaded == false", :before =\> "jira\_loaded = true") %\>

While this works, it bugs me because I know that in the background  
Safari is _constantly_ checking the jira\_loaded condition. What I would  
really like to do is to execute the request just once as the page loads.  
I thought about writing some javascript to do this, registering an  
onLoad event, and then pulling in the data myself, but I really don’t  
want to do that if there is a railsy way to do it instead.

I looked for a call\_remote tag, or something related to it that would  
serve this purpose, to no avail.

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![cvandyck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f6c823/32.png) [@cvandyck](https://www.ruby-forum.com/u/cvandyck)\
**Post date:** [December 19, 2007, 8:28am UTC](https://www.ruby-forum.com/t/how-to-execute-remote-action-once-as-the-page-loads/118548/2 "2007-12-19T08:28:32Z")

</div>

On Oct 28, 8:24 am, Collin V. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Safari is \*constantly\* checking the jira\_loaded condition. What I would Posted viahttp://www.ruby-forum.com/.

Did you ever find a solution for this? I have the same problem: I  
need something like a “call\_remote” function.

I’ve put:

render :update do |page|  
page.call ‘scroll’, 0, 0  
page.replace\_html :campaign\_errors, “ERRORS TEST”  
end

into an action executed in response to a GET request and got back the  
expected text/html response:

try {  
scroll(0, 0);  
Element.update(“campaign\_errors”, “ERRORS TEST” );  
} catch (e) { alert(‘RJS error:\n\n’ + e.toString()); alert(‘scroll(0,  
0);\nElement.update("campaign\_errors", "ERRORS TEST"");’); throw  
e }

displayed, as expected, as text in the browser.

The question seems to boil down to how to call render :update in a xhr  
request that returns text/javascript for execution by the browser?

Any ideas about this?
