I'm collecting latitude and longitude from Mobile Safari with some JavaScript code. After collecting the information from the browser, I want to update the location with an AJAX request. Is there a helper or otherwise simple way to do this with Rails/Prototype or will I have to do an XMLHttpRequest? I only see link_to_remote
, periodically_call_remote
, and form_remote_tag
in the PrototypeHelper API.
views:
176answers:
3
+1
A:
take a look at prototype's ajax call functionality.
new Ajax.Request('/some_url', {
method: 'get',
parameters: {id: "1", latitude: '123.123', longitude: "123.123"},
onSuccess: function(transport){
//Do something?
}
});
Just replace /some_url with your route and the javascript fields. I have included id as a parameter in case you are refering to a model so your action may find it and update it.
Konstantinos
2009-11-09 17:32:01
A:
You could use form_remote_tag
to make a form with some hidden input fields for the data and then submit the form via javascript.
document.form_name.onsubmit();
mckeed
2009-11-09 17:43:19
+2
A:
remote_function
will do what you are looking for. It will also include the Authenticity Token required for Ajax requests.
Swanand
2009-11-09 17:45:51
exactly what I was looking for. thanks.
mculp
2009-11-09 20:32:06