Form target usage to achieve no refreshing of new pages

Source: Internet
Author: User

Target of the Form. When IFRAME is set to hide, the current page form can be submitted without jump refreshing. The Code is as follows: Prepare a form and an IFRAME on the homepage.

Java code
  1. <Form action = "submitted action" method = "Post" target = "myiframe">
  2. .....................
  3. </Form>
  4. <IFRAME name = "myiframe" style = "display: none"> </iframe>
<Form action = "submitted action" method = "Post" target = "myiframe"> ..................... </form> <IFRAME name = "myiframe" style = "display: none"> </iframe>

 

After the action is submitted, the action returns a string of JavaScript statements.

JS Code
  1. String script = "<SCRIPT> alert ('Hello! '); </SCRIPT> ";
  2. Response. getoutputstream (). Write (script. getbytes ("UTF-8 "));
String script = "<SCRIPT> alert ('Hello! '); </SCRIPT> "; response. getoutputstream (). Write (script. getbytes (" UTF-8 "));

 

Alert ('hello') will be executed on the current page. The principle is that the results submitted by form are executed in the IFRAME specified by target,
IFRAME is hidden. In this way, the effect after submission is the same as that after refreshing.

Form target usage to achieve no refreshing of new pages

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.