views:

176

answers:

3

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.

+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
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
+2  A: 

remote_function will do what you are looking for. It will also include the Authenticity Token required for Ajax requests.

Swanand
exactly what I was looking for. thanks.
mculp