I have a simple task that I am struggling with. What I want to achieve is when a button on my HTML JavaScript page is clicked, it sends a large amount of data to the server using the AJAX POST method. The server then uses this data to create an XML file, which is sent back to the user for saving.
My understanding of Ruby on Rails is limited, and despite researching tutorials, I couldn't find any clear explanation on how to handle POST requests. I don't need to make any changes to the HTML page itself, so the section responsible for sending data looks like this:
//data is a huge string already xml > 1mb
xmlhttp=new XMLHttpRequest();
xmlhttp.open('POST', "http://localhost:3000/xmlsave", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(data);
In Rails 3.0, I have /xmlsave routed to an action in a controller I created:
class MyController < ApplicationController
def xmlsave
#Read data sent with POST and put it in generated xml file and send to user
end
end
If I am approaching this correctly, could someone explain to me or guide me on what I should include under the xmlsave method to:
- Retrieve data sent via AJAX POST
- Create an XML file from the existing XML data string
- Send the XML file to the user (using send_file?)
I apologize if my request seems unusual or misguided. Most tutorials I've come across focus on creating partials to modify parts of the HTML page the user is viewing, which is not what I intend to do. The tutorials also lack clarity on handling requests, data processing, function calls, etc., leaving me confused.
Thank you.