I need to retrieve coordinates from an external API, specifically the Google Maps API, and then send it to my controller. However, I am encountering a 500 internal server error when using jQuery/Ajax for this task. Researching the issue online suggests that it could be due to a cross-domain Ajax request. Below are the relevant code snippets in JavaScript and the controller:
JavaScript:
// Here is where the Google Maps API code resides. The points variable represents an object with an array of coordinates.
var points = polyline.GetPointsAtDistance(16000);
$.ajax({
type: "POST",
url: '/pages/calculate',
data: {mydata: points},
success: function(response) {
// Add your response handling logic here
}
});
Controller:
def calculate
x = params[:mydata]
# Perform operations using 'x'...
end
Is there a way to successfully transmit this JavaScript data to the controller? Would submitting the data through a hidden form be a viable alternative? Alternatively, if backend manipulation of Google Maps data is required, should a Google Maps gem be used to handle all data processing on the backend instead?