Ajax submission is related to the difference between the form submission and the _ajax

Source: Internet
Author: User
Tags blank page

Now compare the pros and cons of Ajax with hidden form submissions.

1. Hide form submission, update the data after the completion of the need to go to a blank page and then the original page submitted after processing; Ajax is not, you can directly return to the original page for processing after submission. Visible Ajax can add a page less than the hidden form submission.

2.ajax for security reasons, you cannot operate on files, so you can't upload files through Ajax, and you can do this by hiding form submissions, so this is the main purpose that is currently submitted with a hidden form.

Now let's talk about how to upload files by hiding the form

1 First define a form to fill in the forms

<form name= "Form1" ></form>

2) then define a form for submission

<form name= "Form2" target= "myiframe" >//To specify that the returned page of the submission is displayed in this hidden iframe

<iframe name= "Myiframe" style= "Display:none" ></iframe>//For storing a blank page after submitting the return

<div id= "Forminner" style= "Display:none" ></div>//For obtaining Form1 HTML content, obtaining Form1 form elements

</form>

3 when Form1 commits, the following JavaScript processing is done

var forminner= document.getelementbyid ("Forminner");
forminner.innerhtml = form1.innerhtml; To copy Form1 HTML code
Form2.action = form1.action;
Form2.submit ();

4 after the submission, into the background processing, after the completion of the background processing, you need to return a blank page blank.jsp, this page is generated in the hidden iframe, so you can use the parent object to the original page to operate.

For example, the original page defines a updatepagefromsubmit (), then the blank.jsp page can be called through the Parent.updatepagefromsubmit () to the processing of the return after the submission

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.