How to add key/value pair to existing form data
How to add key/value pair to existing form data
Through the use of the programming language, we will work together to solve the "How to add key/value pair to existing form data" puzzle in this lesson.
You can add key/value to an existing form data while calling the ajax request. Sometimes we have to add extra data to a form data which does not exist in form input elements then we can add this data to existing form data.-
Add key/value pair to existing form data
<script> var id = $('#recordID').val(); formData.append('id', id); //Code snippet with form data $('#form').on('submit', function(e){ e.preventDefault(); var formData = new FormData($(this)[0]); var id = $('#recordID').val(); formData.append('id', id); $.ajax({ type: "POST", dataType: "json", url: "/add-record", data: formData, processData: false, success: function(data){ console.log(data); } }); }) </script>
You have to use formData.append('id', id); to add a new key/value pair to existing form data.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Javascript
- ReferenceError: $ is not defined
- How to fixed bootstrap navbar at top on scroll
- ReferenceError: Cannot access 'myFunction' before initialization
- Hide div on click outside of element in javascript/jQuery
- Apex chart bar chart
- How to echo array in Javascript
- How to validate input type file size in javascript
- How to get data from localstorage in javascript
- How to add a property to object with condition in javascript
- How to preview a word document in HTML using javascript
- Remove hostname from URL in javascript
- Trim the leading and trailing comma from string in Javascript
- Json stringify
- How to remove duplicate values from array in javascript
- How to check file is an image in javascript using filename
- Deault order of record in datatable
- Get hostname from URL in javascript
- How to preview video before uploading in javascript
- How to validate empty space in textbox in Javascript
- Uncaught TypeError: Assignment to constant variable
- Javascript to print Fibonacci series upto 15 Observations
- Cropper js with multiple images
- How to use JavaScript to search for items in a list
- Prism js horizontally overflowing its container
- How to get the length of a number in JavaScript