Whatever you do, it has to involve the server. The client on it's own won't
be able to handle it. See this related thread:

"save as" => save contents of a textbox to a file on client's PC
http://groups.google.com/group/jquery-en/browse_thread/thread/64ca14bd5ddcc86f

- Richard

On Tue, Jul 15, 2008 at 6:08 AM, aharef <[EMAIL PROTECTED]> wrote:

>
> Hi everyone,
>
> I want to allow my Users to download a file containing nothing but a
> string generated in the client. I do have a solution but am rather
> unhappy with it. In brief:
>
> Mission:
> * In my App the User is presented a list of checkboxes to let him
> select which content (already stored in an attribute of each checkbox)
> he wants to download as a XML file - pure clientside. Done.
> * With jQuery my App puts together a string containing XML-markup
> according to User's selection - still clientside. Done.
> * Now I want the User to be able to download the contents of the
> string (with the common "Save as"-dialogue) in a file named
> "MyData.xml" - also clientside...
>
> Solution 1 (please see related code below):
> * Send the string via Ajax to the backend, where a XML-file called
> "MyData.xml" is created on the local drive.
> * If this was successful, window.open() is initiated in the client
> linking the XML-file.
> * User is happy.
>
> Yet I am unhappy with Solution 1 since
> * all data is "uselessly" passed back and forth, even though no
> contents are changed (just the 'formatting' as a file)...
> * the generated file still needs to be unlinked in a further Ajax-call
> after 'x' seconds...
> * the file is actually displayed in the browser :( But thats solvable
> PHP-Offtopic ;)
> Thus I discarded further improvement of Solution 1...
>
> Solution 2:
> * Somehow the string is being 'streamed' into the file-download
> initiated after the User decided to "Save file as" (no rightclick!).
>
> But how? Help! ;) Do you know any tricks or hints to archive Solution
> 2 () with jQuery or Javascript?
> Many thanks in advance and greetings to a great group!
>
> Aharef
>
>
> <code>
>  var filename = "data/MyData.xml";
>  var xmlString = generateXmlString(); // <?xml version="1.0"?
> ><contacts><contact>[EMAIL PROTECTED]</contact><contact>[EMAIL 
> >PROTECTED]</contact></
> contacts>
>
>  jQuery.ajax({
>    url: "createfile.php",
>    data: "&filename="+filename+"&xml="+xmlString+"&",
>    dataType: "html",
>    error: function() { alert("Sorry, couldn't create your
> file..."); },
>    success: function(filename) { window.open(filename,"_blank"); }
>  });
> </code>
>

Reply via email to