jquery post method to pass multiple parameter values the background is received as an array _jquery

Source: Internet
Author: User
When you pass multiple values in jquery post, you can receive them in an array form in the background page

as shown below
Copy Code code 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) {
Empty the contents of the Message text box
$ ("#msg"). Val ("");
Calling a function that parses XML
Addmessages (XML);
});
return false;

})
})
</script>

Passing parameters as an array is not supported in $.post, so it is passed as a string in the jquery code above, and the ASPX page in the background can be split in the form of an array after it is received, as follows
Copy Code code 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];

So we can get the corresponding value.

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.