Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Farnoosh M
Farnoosh M
10,921 Points

Sending the form data to a text file?

Hi! I have this simple form with the action set to 'data/form-info.txt'. When I send the form with jQuery I also call the form data to the console and see that the data is sent.

I was wondering if it's actually possible to save the data in a text file and then get the data later by a get method as a JSON object (Without any server side programming)?

I see that my .txt file is empty after submitting the form so I'm also wondering where the data goes.

        $('#form').submit(function (evt) {
        evt.preventDefault();
        var url = $(this).attr('action');
        // Get all the values from all form fields and encode them
        var formData = $(this).serialize();
         console.log(formData);
         $.post(url, formData, function(response){
           $('div#show-form-data').html('<h3>Thank you for signing up with us!</h3>'+
                          '<img src="img/happy.svg">'); 

         });// end post
    });// end of submit

1 Answer

The short answer is no, it's not possible to save files without some server side programming. If you're comfortable with JavaScript and jQuery, then it's probably worth looking at Node.js next since it is also JavaScript, but running on the server side.

Otherwise PHP probably has the least friction to get up and running and have a page that will take your form data and save it to a file, but it's obviously a completely new programming language...