Now let's compare the advantages and disadvantages of ajax and hidden form submission.
1. Hide form submission. After updating data, you need to go to a blank page and submit the original page for post-processing. ajax does not need to be used. You can directly return to the original page for post-Submission processing. It can be seen that ajax can add a page less than the hidden form commit.
2. for security reasons, ajax does not support file operations. Therefore, it cannot be used to upload files. This function can be implemented by hiding form submission, therefore, this is the main purpose of hidden form submission.
Now we will introduce how to upload files by hiding the form.
1) first define a form used to fill in the form Content
<Form name = "form1"> </form>
2) define a form for submission.
<Form name = "form2" target = "myIframe"> // you can specify that the returned page is displayed in the hidden iframe.
<Iframe name = "myIframe" style = "display: none"> </iframe> // stores the blank page after the return result is submitted.
<Div id = "formInner" style = "display: none"> </div> // gets the html content of form1 and the form element of form1.
</Form>
3) When form1 is submitted, perform the following javascript processing:
Var formInner = document. getElementById ("formInner ");
FormInner. innerHTML = form1.innerHTML; // copy the html code of form1
Form2.action = form1.action;
Form2.submit ();
4) after submission, go to the background for processing. After the background processing is complete, you need to return a blank page blank. jsp, this page is generated in the hidden iframe, so you can operate the original page through the parent object.
For example, if the original page defines an updatePageFromSubmit (), you can use parent. updatePageFromSubmit () on the blank. jsp page to call it for processing after the return is submitted.