# How to remote function to get info from url in a javascript function

**URL:** <https://www.ruby-forum.com/t/how-to-remote-function-to-get-info-from-url-in-a-javascript-function/195404>\
**Category:** Rails\
**Created:** [September 22, 2010, 8:22pm UTC](https://www.ruby-forum.com/t/how-to-remote-function-to-get-info-from-url-in-a-javascript-function/195404 "2010-09-22T20:22:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [September 22, 2010, 8:22pm UTC](https://www.ruby-forum.com/t/how-to-remote-function-to-get-info-from-url-in-a-javascript-function/195404/1 "2010-09-22T20:22:39Z")

</div>

hey all

I am working with a javascript function called Elabel, part of the  
Google maps api  
the Elabel has a function called setContents(html)

i need to be able to call this function and get new html for it. ( the  
html is a table that displays weather data)

here is what i have so far

function replace\_weather\_table(){  
zoomy = map.getZoom();  
weather\_table\_one.setContents(new Ajax.Request(’/weather/  
update\_weather\_tables?zoom=’+zoomy));  
};

GEvent.addListener(map,“moveend”, replace\_weather\_table);

i would like to have the contents be those of a partial, but when  
executed, the display only shows “[object Object]”

would appreciate any help, thanks

sk

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [September 22, 2010, 10:19pm UTC](https://www.ruby-forum.com/t/how-to-remote-function-to-get-info-from-url-in-a-javascript-function/195404/2 "2010-09-22T22:19:11Z")

</div>

make a controller respond to ajax and return a .js.erb it will be  
evaluated  
dynamically.

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [September 22, 2010, 10:25pm UTC](https://www.ruby-forum.com/t/how-to-remote-function-to-get-info-from-url-in-a-javascript-function/195404/3 "2010-09-22T22:25:02Z")

</div>

load jquery first and perform a $.get([controller\_path], null,  
null,‘script’)

return a whatever.js.erb with a content like

$("#thingy").html("\<%=escape\_javascript(render :partial  
=\>“controller/whatever”)%\>");

---

<div class="post-metadata">

**Author:** ![nephish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/8e7dd6/32.png) [@nephish](https://www.ruby-forum.com/u/nephish)\
**Post date:** [September 23, 2010, 4:25pm UTC](https://www.ruby-forum.com/t/how-to-remote-function-to-get-info-from-url-in-a-javascript-function/195404/4 "2010-09-23T16:25:02Z")

</div>

Shawn B. wrote:

> hey all
> 
> I am working with a javascript function called Elabel, part of the  
> Google maps api  
> the Elabel has a function called setContents(html)
> 
> i need to be able to call this function and get new html for it. ( the  
> html is a table that displays weather data)

I don’t understand your logic flow. Can you clarify?

> here is what i have so far
> 
> function replace\_weather\_table(){  
> zoomy = map.getZoom();  
> weather\_table\_one.setContents(new Ajax.Request(‘/weather/  
> update\_weather\_tables?zoom=’+zoomy));  
> };
> 
> GEvent.addListener(map,“moveend”, replace\_weather\_table);
> 
> i would like to have the contents be those of a partial, but when  
> executed, the display only shows “[object Object]”

Is the new HTML rendered by your Rails app, then, or does it come from a  
remote server?

> would appreciate any help, thanks
> 
> sk

## Best,

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