# Executing js when a partial loads

**URL:** <https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028>\
**Category:** rubyonrails-talk\
**Created:** [July 6, 2009, 11:40pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028 "2009-07-06T23:40:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![JannaB](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@JannaB](https://discuss.rubyonrails.org/u/JannaB)\
**Post date:** [July 6, 2009, 11:40pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/1 "2009-07-06T23:40:30Z")

</div>

In my view I have a:

\<%= render :partial =\> 'uplog' %\>

and the partial is shown below. Note there is js in it which I thought got executed on load (but, I have found out this does NOT happen when a partial is loaded. How else can I execute the js below when the partial gets loaded (someone said to call it explicitly....but how and from where?) THanks, Janna B

\<div id="namesdata" style="float: left; width: 200px;"\> names \</div\> \<div id="rowsdata" style="float: left; "\> rows \</div\> \<script\> startClock('../../../../www/test/ggriptest/getdata1.dat','./ getdata2.php'); \</script\>

---

<div class="post-metadata">

**Author:** ![Bill\_Walton1](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Bill\_Walton1](https://discuss.rubyonrails.org/u/Bill_Walton1)\
**Post date:** [July 7, 2009, 12:49am UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/2 "2009-07-07T00:49:31Z")

</div>

Not tested, but I believe you can add the onload to the div.

\<div id="namesdata" style="float: left; width: 200px;" onload="startClock('your parameters' in single quotes')"\>

---

<div class="post-metadata">

**Author:** ![JannaB](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@JannaB](https://discuss.rubyonrails.org/u/JannaB)\
**Post date:** [July 7, 2009, 12:57am UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/3 "2009-07-07T00:57:26Z")

</div>

Thanks but that doesn't work in a partial.

---

<div class="post-metadata">

**Author:** ![Don\_Hill](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@Don\_Hill](https://discuss.rubyonrails.org/u/Don_Hill)\
**Post date:** [July 7, 2009, 1:45am UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/4 "2009-07-07T01:45:47Z")

</div>

I don’t think any javascript will get executed until the document is ready at which time onload will get fired. You could put the code in the body on load but that wouldn’t help in the partial.

You could use some jquery script and register a functioncall like

names

rows

---

<div class="post-metadata">

**Author:** ![JannaB](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@JannaB](https://discuss.rubyonrails.org/u/JannaB)\
**Post date:** [July 7, 2009, 9:06am UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/5 "2009-07-07T09:06:04Z")

</div>

No, nor does this work in a partial.

---

<div class="post-metadata">

**Author:** ![Bill\_Walton1](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Bill\_Walton1](https://discuss.rubyonrails.org/u/Bill_Walton1)\
**Post date:** [July 7, 2009, 2:26pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/6 "2009-07-07T14:26:54Z")

</div>

You haven't said what triggers the load of the partial. If you can make that event an Ajax event, then you can trigger the execution of the JS directly in an RJS template. The only problem I'd potentially anticipate would be if the browser decided to execute the JS prior to the completion of the rendering of the partial. Shouldn't happen, but if it did, you could just put the function in application.js and it would already be there.

If you go this route, the only 'tricky' part I ran across was understanding that, assuming your JS signature looks like this:

startClock('arg1');

The RJS signature looks like this:

page.call "startClock" "arg1"

HTH, Bill

---

<div class="post-metadata">

**Author:** ![Naren1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Naren1](https://discuss.rubyonrails.org/u/Naren1)\
**Post date:** [July 7, 2009, 2:34pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/7 "2009-07-07T14:34:08Z")

</div>

what exactly happen , when partial loaded ? any error ?

~ N a R e N

---

<div class="post-metadata">

**Author:** ![Vitaly\_Kushner1](https://avatars.discourse-cdn.com/v4/letter/v/dc4da7/32.png) [@Vitaly\_Kushner1](https://discuss.rubyonrails.org/u/Vitaly_Kushner1)\
**Post date:** [July 7, 2009, 3:11pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/8 "2009-07-07T15:11:19Z")

</div>

Note that there is nothing special about the partial. The browser has no idea if the code came from a single template or was generated from the partials. So if something doesn't work its unrelated to the partial. Anyway.... if you have a javascript on that page that does gets executed you can \*add\* more code to the same spot from the partial like this:

\<% content\_for :on\_load do %\> &nbsp;&nbsp;.... js code to run on load \<% end %\>

wherever you have a js code that runs on the load just add: \<%= yield :on\_load %\>

And it will add whatever was added in the partial. Note that it will work if the yield is in the layout or in the template \*after\* the rendering of the partial, this is because when it runs the partial must have run already (and layouts code is the last to execute btw, so that if you do \<% @qwe = 123 %\> anywhere in the templates or partials it will be available in the layout)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![JannaB](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@JannaB](https://discuss.rubyonrails.org/u/JannaB)\
**Post date:** [July 7, 2009, 3:12pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/9 "2009-07-07T15:12:28Z")

</div>

Nothing happens. Nothing at all. I see "rows" and "names" printed up, but in my uplog.js, which contains the function startclock(..) which has an alert in it, evidently never gets called. Worse yet, I get a peculiar error in the Firefox Error Console when I click on the link\_to\_remote link (the error is simply "Permission denied to call method Location.toString). I am including all of the code below.

## Here is my partial that gets called:

\<div id="namesdata" style="float: left; width: 200px;" \> names \<%= link\_to\_remote("StartClock", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:url =\>{ :action =\> :clockstarter }) %\> \</div\> \<div id="rowsdata" style="float: left; "\> rows \</div\>

## Here is clockstarter.rjs:

page.call "startClock" "../../../../www/test/ggriptest/getdata1.dat" "./getdata2.php'"

## This is in my layout, which the partial is loaded into:

\<%= javascript\_include\_tag "uplog" %\>

## Here is /public/javascripts/uplog.js

if (window.ActiveXObject && !window.XMLHttpRequest) {

&nbsp;&nbsp;window.XMLHttpRequest = function() {

&nbsp;&nbsp;&nbsp;&nbsp;var msxmls = new Array(

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Msxml2.XMLHTTP.6.0',

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Msxml2.XMLHTTP.5.0',

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Msxml2.XMLHTTP.4.0',

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Msxml2.XMLHTTP.3.0',

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Msxml2.XMLHTTP',

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Microsoft.XMLHTTP');

&nbsp;&nbsp;&nbsp;&nbsp;for (var i = 0; i \< msxmls.length; i++) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return new ActiveXObject(msxmls[i]);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch (e) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;return null;

&nbsp;&nbsp;};

}

// Gecko support

/\* 😉 \*/

// Opera support

if (window.opera && !window.XMLHttpRequest) {

&nbsp;&nbsp;window.XMLHttpRequest = function() {

&nbsp;&nbsp;&nbsp;&nbsp;this.readyState = 0; // 0=uninitialized,1=loading,2=loaded, 3=interactive,4=complete

&nbsp;&nbsp;&nbsp;&nbsp;this.status = 0; // HTTP status codes

&nbsp;&nbsp;&nbsp;&nbsp;this.statusText = '';

&nbsp;&nbsp;&nbsp;&nbsp;this.\_headers = ;

&nbsp;&nbsp;&nbsp;&nbsp;this.\_aborted = false;

&nbsp;&nbsp;&nbsp;&nbsp;this.\_async = true;

&nbsp;&nbsp;&nbsp;&nbsp;this.\_defaultCharset = 'ISO-8859-1';

&nbsp;&nbsp;&nbsp;&nbsp;this.\_getCharset = function() {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var charset = \_defaultCharset;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var contentType = this.getResponseHeader('Content- type').toUpperCase();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = contentType.indexOf('CHARSET=');

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (val != -1) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;charset = contentType.substring(val);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = charset.indexOf(';');

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (val != -1) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;charset = charset.substring(0, val);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = charset.indexOf(',');

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (val != -1) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;charset = charset.substring(0, val);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return charset;

&nbsp;&nbsp;&nbsp;&nbsp;};

&nbsp;&nbsp;&nbsp;&nbsp;this.abort = function() {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.\_aborted = true;

&nbsp;&nbsp;&nbsp;&nbsp;};

&nbsp;&nbsp;&nbsp;&nbsp;this.getAllResponseHeaders = function() {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return this.getAllResponseHeader('\*');

&nbsp;&nbsp;&nbsp;&nbsp;};

&nbsp;&nbsp;&nbsp;&nbsp;this.getAllResponseHeader = function(header) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var ret = '';

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i = 0; i \< this.\_headers.length; i++) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (header == '\*' || this.\_headers[i].h == header) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ret += this.\_headers[i].h + ': ' + this.\_headers[i].v + '\n';

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ret;

&nbsp;&nbsp;&nbsp;&nbsp;};

&nbsp;&nbsp;&nbsp;&nbsp;this.getResponseHeader = function(header) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var ret = getAllResponseHeader(header);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var i = ret.indexOf('\n');

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (i != -1) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ret = ret.substring(0, i);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ret;

&nbsp;&nbsp;&nbsp;&nbsp;};

&nbsp;&nbsp;&nbsp;&nbsp;this.setRequestHeader = function(header, value) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.\_headers[this.\_headers.length] = {h:header, v:value};

&nbsp;&nbsp;&nbsp;&nbsp;};

&nbsp;&nbsp;&nbsp;&nbsp;this.open = function(method, url, async, user, password) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.method = method;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.url = url;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.\_async = true;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.\_aborted = false;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.\_headers = ;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (arguments.length \>= 3) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.\_async = async;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (arguments.length \> 3) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;opera.postError('XMLHttpRequest.open() - user/password not supported');

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.readyState = 1;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.onreadystatechange) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.onreadystatechange();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;};

&nbsp;&nbsp;&nbsp;&nbsp;this.send = function(data) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!navigator.javaEnabled()) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("XMLHttpRequest.send() - Java must be installed and enabled.");

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.\_async) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setTimeout(this.\_sendasync, 0, this, data);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// this is not really asynchronous and won't execute until the current

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// execution context ends

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.\_sendsync(data);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;this.\_sendasync = function(req, data) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!req.\_aborted) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;req.\_sendsync(data);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;};

&nbsp;&nbsp;&nbsp;&nbsp;this.\_sendsync = function(data) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.readyState = 2;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.onreadystatechange) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.onreadystatechange();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// open connection

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var url = new java.net.URL(new java.net.URL (window.location.href), this.url);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var conn = url.openConnection();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i = 0; i \< this.\_headers.length; i++) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.setRequestProperty(this.\_headers[i].h, this.\_headers [i].v);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.\_headers = ;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.method == 'POST') {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// POST data

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.setDoOutput(true);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var wr = new java.io.OutputStreamWriter(conn.getOutputStream (), this.\_getCharset());

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wr.write(data);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wr.flush();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wr.close();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// read response headers

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// NOTE: the getHeaderField() methods always return nulls for me ☹

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var gotContentEncoding = false;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var gotContentLength = false;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var gotContentType = false;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var gotDate = false;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var gotExpiration = false;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var gotLastModified = false;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i = 0; ; i++) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var hdrName = conn.getHeaderFieldKey(i);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var hdrValue = conn.getHeaderField(i);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (hdrName == null && hdrValue == null) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (hdrName != null) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.\_headers[this.\_headers.length] = {h:hdrName, v:hdrValue};

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch (hdrName.toLowerCase()) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 'content-encoding': gotContentEncoding = true; break;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 'content-length' : gotContentLength = true; break;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 'content-type' : gotContentType = true; break;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 'date' : gotDate = true; break;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 'expires' : gotExpiration = true; break;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case 'last-modified' : gotLastModified = true; break;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// try to fill in any missing header information

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var val;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = conn.getContentEncoding();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (val != null && !gotContentEncoding) this.\_headers [this.\_headers.length] = {h:'Content-encoding', v:val};

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = conn.getContentLength();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (val != -1 && !gotContentLength) this.\_headers [this.\_headers.length] = {h:'Content-length', v:val};

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = conn.getContentType();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (val != null && !gotContentType) this.\_headers [this.\_headers.length] = {h:'Content-type', v:val};

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = conn.getDate();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (val != 0 && !gotDate) this.\_headers[this.\_headers.length] = {h:'Date', v:(new Date(val)).toUTCString()};

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = conn.getExpiration();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (val != 0 && !gotExpiration) this.\_headers [this.\_headers.length] = {h:'Expires', v:(new Date(val)).toUTCString ()};

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;val = conn.getLastModified();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (val != 0 && !gotLastModified) this.\_headers [this.\_headers.length] = {h:'Last-modified', v:(new Date (val)).toUTCString()};

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// read response data

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var reqdata = '';

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var stream = conn.getInputStream();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (stream) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var reader = new java.io.BufferedReader(new java.io.InputStreamReader(stream, this.\_getCharset()));

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var line;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while ((line = reader.readLine()) != null) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.readyState == 2) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.readyState = 3;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.onreadystatechange) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.onreadystatechange();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reqdata += line + '\n';

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;reader.close();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.status = 200;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.statusText = 'OK';

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.responseText = reqdata;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.readyState = 4;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.onreadystatechange) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.onreadystatechange();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.onload) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.onload();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// error

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.status = 404;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.statusText = 'Not Found';

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.responseText = '';

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.readyState = 4;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.onreadystatechange) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.onreadystatechange();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (this.onerror) {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.onerror();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;};

&nbsp;&nbsp;};

}

function startClock(namedata,rowsdata){ &nbsp;&nbsp;alert(namedata); setTimeout("startClock()", 2000); getNames(namedata); getRows(rowdata); }

var req;

function getNames(namedata){ req = new XMLHttpRequest(); if(req){ req.onreadystatechange=processReqChange1; &nbsp;&nbsp;try{ &nbsp;&nbsp;&nbsp;&nbsp;req.open('GET', namedata);

&nbsp;&nbsp;&nbsp;&nbsp;req.setRequestHeader('If-Modified-Since' ,'Sat, 1 Jan 1900 00:00:00 GMT'); &nbsp;&nbsp;req.send(""); &nbsp;&nbsp;}catch(e){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(e); &nbsp;&nbsp;} } }

function getRows(rowdata){ req = new XMLHttpRequest(); if(req){ req.onreadystatechange=processReqChange2; &nbsp;&nbsp;try{ &nbsp;&nbsp;&nbsp;&nbsp;req.open('GET', rowdata); &nbsp;&nbsp;&nbsp;&nbsp;req.setRequestHeader('If-Modified-Since' ,'Sat, 1 Jan 1900 00:00:00 GMT'); &nbsp;&nbsp;req.send(""); &nbsp;&nbsp;}catch(e){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(e); &nbsp;&nbsp;} } }

function processReqChange1(){ &nbsp;&nbsp;if(req.readyState == 4 && (req.status == 200 || req.status == 304)){ &nbsp;&nbsp;&nbsp;&nbsp;var rows = eval(req.responseText); &nbsp;&nbsp;&nbsp;&nbsp;var html = "\<br\>\<br\>\<table\>";

&nbsp;&nbsp;&nbsp;&nbsp;for(r in rows){ &nbsp;&nbsp;if(rows[r].status=="-1") &nbsp;&nbsp;&nbsp;&nbsp;html+="\<tr\>\<td\>\<FONT COLOR=\"#4B7399\"\>"+rows[r].order+". "+rows [r].username+"\</FONT\>\</td\>\</tr\>"; &nbsp;&nbsp;else if(rows[r].status=="0") &nbsp;&nbsp;&nbsp;&nbsp;html+="\<tr\>\<td\>"+rows[r].order+". "+rows[r].username+"\</td\>\</tr\>"; &nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;html+="\<tr\>\<td bgcolor=\"#4B7399\"\>\<FONT COLOR=\"#FFFFFF\"\>"+rows [r].order+". "+rows[r].username+"\</td\>\</tr\>"; } &nbsp;&nbsp;&nbsp;&nbsp;html+="\</table\>"; &nbsp;&nbsp;&nbsp;&nbsp;document.getElementById("rowsdata").innerHTML = html; &nbsp;&nbsp;} }

function processReqChange2(){ &nbsp;&nbsp;if(req.readyState == 4 && (req.status == 200 || req.status == 304)){ &nbsp;&nbsp;&nbsp;&nbsp;var rows = eval(req.responseText); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var html=rows[0].totals+" ups for today for \<b\>\<u\>"+rows[0].room +"\</b\>\</u\>\<br\>\<br\>\<table\>"; &nbsp;&nbsp;html+="\<tr align=\"center\" valign=\"top\" bgcolor=\"#C0C0C0\"\>"; &nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> #\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> Day\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> Time\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> Sensor\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> Heads\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> Associate\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> CXL\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> BB\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> TO\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> DR\</th\>";

&nbsp;&nbsp;html+="\<th valign=\"top\" align=\"center\" bgcolor=\"#C0C0C0\"

> OK\</th\>";

&nbsp;&nbsp;html+="\</tr\>"; &nbsp;&nbsp;&nbsp;&nbsp;var k=-1; &nbsp;&nbsp;&nbsp;&nbsp;for(r in rows){ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;k++; &nbsp;&nbsp;&nbsp;&nbsp;if(k\>0){ &nbsp;&nbsp;&nbsp;&nbsp;html+="\<tr\>"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html+="\<td\>"+rows[r].dayno+"\</td\>\<td\>"+rows[r].dof+"\</

> \<td\>"+rows[r].time+"\</td\>\<td\>"+rows[r].sensor+"\</td\>\<td\>"+rows

[r].hits+"\</td\>\<td\>"+rows[r].assoc+"\</td\>\<td\>"+"CXL"; &nbsp;&nbsp;&nbsp;&nbsp;if(rows[r].bb==-1) &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td bgcolor=\"#FFFFFF\"\>"+"BB"; &nbsp;&nbsp;&nbsp;&nbsp;else if(rows[r].bb==1) &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td bgcolor=\"#1F7F00\"\>"+"BB"; &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td\>"+"BB"; &nbsp;&nbsp;&nbsp;&nbsp;if(rows[r].tor==-1) &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td bgcolor=\"#FFFFFF\"\>"+"TO"; &nbsp;&nbsp;&nbsp;&nbsp;else if(rows[r].tor==1) &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td bgcolor=\"#1F7F00\"\>"+"TO"; &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td\>"+"TO"; &nbsp;&nbsp;&nbsp;&nbsp;if(rows[r].dr==-1) &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td bgcolor=\"#FFFFFF\"\>"+"DR"; &nbsp;&nbsp;&nbsp;&nbsp;else if(rows[r].dr==1) &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td bgcolor=\"#1F7F00\"\>"+"DR"; &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td\>"+"DR"; &nbsp;&nbsp;&nbsp;&nbsp;html+="\</td\>\<td\>"+"OK"+"\</td\>"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;html+="\</tr\>"; &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp;&nbsp;&nbsp;html+="\</table\>"; &nbsp;&nbsp;&nbsp;&nbsp;document.getElementById("namesdata").innerHTML = html; &nbsp;&nbsp;} }

---

<div class="post-metadata">

**Author:** ![Naren1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Naren1](https://discuss.rubyonrails.org/u/Naren1)\
**Post date:** [July 7, 2009, 3:20pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/10 "2009-07-07T15:20:58Z")

</div>

there might be some problem in you arguments specially second one. For checking the same just pass an empty string to it and check if the alert is coming .

~ N a R e N

---

<div class="post-metadata">

**Author:** ![JannaB](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@JannaB](https://discuss.rubyonrails.org/u/JannaB)\
**Post date:** [July 7, 2009, 5:18pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/11 "2009-07-07T17:18:58Z")

</div>

Naren,

Ok, in my rjs I pass it:

page.call "startClock" "" ""

Still, nothing happend (but no error in firebug console now) -Janna

---

<div class="post-metadata">

**Author:** ![Naren1](https://avatars.discourse-cdn.com/v4/letter/n/a4c791/32.png) [@Naren1](https://discuss.rubyonrails.org/u/Naren1)\
**Post date:** [July 7, 2009, 5:24pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/12 "2009-07-07T17:24:57Z")

</div>

your call is not valid ,

use , between arguments and method like this page.call “startClock”, “”, “”

N A R E N

---

<div class="post-metadata">

**Author:** ![JannaB](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@JannaB](https://discuss.rubyonrails.org/u/JannaB)\
**Post date:** [July 7, 2009, 5:33pm UTC](https://discuss.rubyonrails.org/t/executing-js-when-a-partial-loads/44028/13 "2009-07-07T17:33:50Z")

</div>

Thank you Naren. The solution proposed by Vitaly I just tried out and it works! However, I have:

startClock("../../../../public/test/ggriptest/ getdata1.dat","../../../../public/test/ggriptest/getdata2.dat");

my app (this particular partial) is in

G:\InstantRails\rails\_apps\ggripv2\app\views\channels

and the two .dat files (which contain JSON data) are at:

G:\InstantRails\rails\_apps\ggripv2\public\test\ggriptest

Am I specifying this correctly in the parameters above? -Janna
