0

Can I save the form data as a .txt file or .json file on my system using Fetch API in JavaScript. I dont want the form data to be saved in some PHP file

<div>
     <form>
         Name:<br>
     <input type="text" id="fname" name="firstname"><br><br>
            Phone No:<br>
     <input type="text" id="ph" name="lastname"><br><br>
            Designation:<br>
     <input type="text" id="des" name="designation"><br><br><br><br>
     <input type="button" value="Update" onclick="getdata()"</button>
            <button name="cancel">Cancel</button>
     </form>
</div>
<script>
function getdata(){
            var name = document.getElementById('fname').value; 
            var ph = document.getElementById('ph').value; 
            var des = document.getElementById('des').value;  
            alert(name);
      }
</script>

3
  • 1
    Is the app hosted in electron (it's tagged, but not specified in your post directly)? If so, yes, you can save it. Otherwise, no. Commented Jun 27, 2019 at 8:20
  • Check this Answer: stackoverflow.com/a/49924172/5909026 Commented Jun 27, 2019 at 9:00
  • I am making a Native App for that i need to generate .json file for further processing in python. Commented Jun 27, 2019 at 10:53

1 Answer 1

1

No, you can not, FetchAPI is HTTP client and you need server to receive your HTTP request you sent with Fetch and save data from that request to file. It can be HTTP server written in any language: php, node, c#, etc.

You can, however, prompt user to download text file you generated via JS in browser. If it is what you need, you'll need to refer to FileReader API and/or change your question

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.