Save form data into local json file using jquery
forms, javascript, jquery, json
Solution
You need to post data to a simple php file...
like `url: 'story.php'` In that php file create a 'story.json' using `fopen` and store that json
EDIT: if you want to use `serialize()` than use someting like this
data:{'mydata':$(this).serialize()}
and in php file
parse_str($_POST['mydata'],$newarray) ;
echo json_encode($newarray);
Problem
I have a basic form with some input fields. I want to save the form data into a json file on submitting the form. The format of the saved data in the json file should be like this. ``` [ {"title":"some text","description":"some text","info":"some text","username":"some name"}, {"title":"some text","description":"some text","info":"some text","username":"some name"}, {"title":"some text","description":"some text","info":"some text","username":"some name"} ] ``` I tried doing this by using this code, but no data is saved in my 'story.json file' ``` $('form').submit(function() { $.ajax({ type: 'POST', dataType: 'json', url: 'story.json', data: $(this).serialize(), success: function(data) { alert(data.message); }, failure: function (data) { alert('Please try again'); } }); }); ``` I want to save this form data on my local file. Please help me to find the correct way of doing this. Thanks