In the process of doing the project encountered in order to submit form form to Ajax submission, the following is how I summarized the form form submission seamlessly into the Ajax method of submission.
The original form table Danchang this:
<form action= "xxx" method= "get" >//The value of the action is the requested URL address<div class= "Form-group" > <label for= "Name" > name </label> <input type= "text" class= "Form-control" name= "name" > </div> <div C lass= "Form-group" > <label for= "Jobnumber" > Work No. </label> <input type= "number" class= "Form-control" name= "Jobnumber" > </div> <div class= "Form-group" > <label for= "Nation" > Nationalities </label> <input type= "text" class= "Form-control" name= "Nation" > </div> <d IV class= "Form-group" > <label for= "Gender" > Gender </label> <input type= "text" class= "Form-control" name= "Gender" > </div>
<div class= "Modal-footer" >
<button type= "button" class= "btn Btn-default" data-dismiss= "modal" >Close</button>
<button type= "Submit" class= "BTN btn-primary" > Submit </button>
</div>
</Form>
To convert to an AJAX submission, you need to make the following changes:
1. Remove the attribute action and method of the form element, add id= "MyForm", and the form element becomes <form id= "MyForm" >
2. Change the Type= "submit" button to Type= "button"
3. Write in JS file
$ (function() { $.ajax ({ "GET", "xxx", function (data) { console.log (data); // data is returned in the background }});
In this way, you can happily convert form form submissions to AJAX requests.
PS: If you want to include a custom HTTP header in an AJAX request, add the
function (Request) {Request.setrequestheader ("Content-type", "Application/json");
In this way, you can set a custom HTTP header field},
Form form submission to Ajax submission