how to call link_to from javascript

Go To StackoverFlow.com

0

I have some specific situation, I have to initiate remote ajax call from javascript (using serial port to read rfid data) and I want to send it and get ajax response. This is what I want to call:

<%= link_to "evidentiraj", {:action => 'time', :id=>25}, :remote => true %>

I tried manually to start xmlhttp.opetn from javascript, but it does not work:

xmlhttp.open("GET","/evidentiraj/time?id=23",true);
xmlhttp.send();

Thank you. Dorijan

2012-04-04 17:35
by user899119


0

You can run rake routes and look for the url you need, I think it should be something like time_evidentiraj. Then, in your view:

xmlhttp.open("GET","<%= time_evidentiraj_path(@evidentiraj) %>",true);
xmlhttp.send();
2012-04-04 17:42
by alf
Thank you for replay, <%= timeevidentirajpath(:id=>23) %> correctly translate to "/evidentiraj/time?id=23" but it is not working as I expect. Maybe the problem is in some security? In my time action, I am returning format.js, which is some javascript that refresh some divs - user899119 2012-04-04 17:54
Ah, then you need to specify the format too. Try using time_evidentiraj_path(:id=>23, :format => 'js') - alf 2012-04-04 18:10
Ads