The jquery post method transmits multiple parameter values and the background receives them in an array.

Source: Internet
Author: User

When multiple values are transmitted using the post method of jquery, the backend page can receive values in array format.

As shown below Copy codeThe Code is as follows: <script type = "text/javascript">
$ (Function (){
Timestamp = 0;
$ ("# Chatform"). submit (function (){
Var message = $ ("# msg"). val ();
Var name = $ ("# author"). val ();
Var action = "postmsg ";
Var time = timestamp;
$. Post (
"Backend. aspx ",{
Arr: message + "," + name + "," + action + "," + time

}, Function (xml ){
// Clear the content in the message text box
$ ("# Msg"). val ("");
// Call the function for parsing xml
AddMessages (xml );
});
Return false;

})
})
</Script>

To $. the post method does not support passing parameters in the form of arrays. Therefore, it is passed as a string in the above jquery code. The aspx page in the background can be split as an array after receiving, the Code is as follows:Copy codeThe Code is as follows: string arr = Request ["arr"]. ToString ();
String [] myarr = arr. Split (',');
String message = myarr [0];
String name = myarr [1];
String action = myarr [2];
String time = myarr [3];

In this way, the corresponding value is obtained.

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.