Jump to content

Download xml files from server as a zipped file


centaur
 Share

Recommended Posts

Hello everyone,I am new to using Javascript/AJAX.I am developing a web based application where I prompt the used to download some xml files(through a button) from the server. I want the files to be downloaded as a single zip file. Can you drop some hints how I can do this? I have used AJAX to establish connection with the server and want to write a javascript code to do the above task.Thanks in advance..!!!Have a nice day!!! :)--Centaur

Link to comment
Share on other sites

Let's clarify what you mean by download.A common AJAX task is to request XML data and turn it into an XML Document Object which can then be read and manipulated using DOM methods. Is that what you mean? If it is, I'm unaware of a way for JavaScript to unzip a file, and I doubt it will happen automatically. I could be wrong, though.Or do you want to download a file in a way that prompts the user to save the file? If this is the case, the real work will take place on your server. What server-side language are you using? How well can you use it?

Link to comment
Share on other sites

Let's clarify what you mean by download.A common AJAX task is to request XML data and turn it into an XML Document Object which can then be read and manipulated using DOM methods. Is that what you mean? If it is, I'm unaware of a way for JavaScript to unzip a file, and I doubt it will happen automatically. I could be wrong, though.Or do you want to download a file in a way that prompts the user to save the file? If this is the case, the real work will take place on your server. What server-side language are you using? How well can you use it?
Its like I have server response files(response1.xml, response2.xml) stored on the server. When the user on the client side clicks the button, the user should get a prompt to select the location and save the files onto the client machine.Additionally, if the files can be obtained as a single zip file, that would be all the more better. If its not possible to zip the files, then I would still be pleased to know about just saving the files on the client.Thank you for taking your time out for replying to the post :)--Centaur
Link to comment
Share on other sites

If it's Javascript only, then you have to send each file individually. If PHP is an option then you could have PHP create a zip file and send it to the user.
I am afraid but PHP is not an option.My intention is to write a client side script that is handling and processing server responses(xml files). So, the job of the server is just to deliver the files asked by the client. All the other processing and error handling has to be done by the client itself. The server performs additional processing before generating those files but that is not what I need to be worried about right now.A very primitive idea that I have got about doing this task is:req = loadXMLdoc(url); // req is the xmlhttprequest object herevar xmlcontent = req.responseXML;Now, what I can do possibly is to save this 'xmlcontent' in a new document(a xml file) and save it simultaneously by writing a javascript code. Because I am very new to AJAX, I cannot figure out the code and syntax to do this.So, I needed help.Thanks for replying to the thread :)--Centaur
Link to comment
Share on other sites

Javascript can't save files. The server will actually need to send the content in a way that allows the user to save it instead of having the browser just open it (the browser will open and display XML files by default unless the server tells it otherwise). Usually when we have a PHP download script, for example, we have PHP send a certain content-type header that tells the browser to show the save/open dialog box. If the server just sends a regular XML content type then the browser will just open it. Javascript can get the response and display it somewhere else, but once it has the response it can't retroactively show the save dialog box. If Javascript is your only option then you may need to print the XML response in a text area and tell them to select and copy it. There's not a real good way otherwise without control of the server.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...