Implement the post method in Javascript to pass the submitted data

Source: Internet
Author: User

Jspost is actually very easy to submit data. We only need to create a form using js and set form method to post. We have organized the following two instances and hope to help you.

Example 1

The Code is as follows: Copy code

Var myForm = document. createElement ("form ");
MyForm. method = "get ";
MyForm. action = "line_ticket.aspx ";
Var myInput = document. createElement ("input ");
MyInput. setAttribute ("name", "id ");
MyInput. setAttribute ("value", idStr );
MyForm. appendChild (myInput );

Var myInput2 = document. createElement ("input ");
MyInput2.setAttribute ("name", "fid ");
MyInput2.setAttribute ("value", fid );
MyForm. appendChild (myInput2 );

Var myInput3 = document. createElement ("input ");
MyInput3.setAttribute ("name", "unlock ");
MyInput3.setAttribute ("value", unlock );
MyForm. appendChild (myInput3 );

Var myInput4 = document. createElement ("input ");
MyInput4.setAttribute ("name", "Option ");
MyInput4.setAttribute ("value", "del ");
MyForm. appendChild (myInput4 );
Document. body. appendChild (myForm );
MyForm. submit ();
Document. body. removeChild (myForm );


Example 2
 

The Code is as follows: Copy code
<Script type = "text/javascript">
Function postwith (to, p ){
Var myForm = document. create_r_relement_x ("form ");
MyForm. method = "post ";
MyForm. action =;
For (var k in p ){
Var myInput = document. create_r_relement_x ("input ");
MyInput. setAttribute ("name", k );
MyInput. setAttribute ("value", p [k]);
MyForm. a (myInput );
}
Document. body. a (myForm );
MyForm. submit ();
Document. body. removeChild (myForm );
}
</Script>

 
 
Hyperlink code:

The Code is as follows: Copy code
 
<A href = "javascript: postwith ('est est. action ', {'currentpage': '2', 'xisuo': 'computer '}) "> use js to post </a>

 
After clicking the hyperlink, you can send the values of currentPage and xisuo to datatest. action in the form of post for processing, especially when processing multiple parameters.

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.