I want to do something quite simple. Click a button on my html javascript page which sends a bunch of data to the server using the AJAX Post method. The server uses the data sent by the POST method to generate an xml file which it then sends back to the user so they can save it.
My knowledge of ruby on rails is very limited and I've looked at tutorials but none of them seem to simply explain how to handle POST requests. I don't need anything modified on the HTML page itself so the entire html page is static with the sending data part looking like:
//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 made:
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 even doing this correctly, can anybody explain to me or point me in the right direction to what I need to put under the xmlsave method to:
- Read data which was sent with AJAX POST
- Generate xml file from data string which is already xml.. just want to copy paste it into the contents of xml file I want to send back
- Send xml file to user (send_file ?)
I apologize if what I am trying to do is just completely bizarre or I have a completely wrong idea. Most of the tutorials I read go in the direction of creating partials using to edit parts of the html page the user is already looking at which I don't want to do. None of the tutorials I read seem to explain exactly where requests go and where data goes and where I should call functions etc and I am confused.
Thank you.