Differences between AJAX submission and FORM submission

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.