Jsp implements the checkbox ajax value passing instance, checkboxajax

Source: Internet
Author: User

Jsp implements the checkbox ajax value passing instance, checkboxajax

This example describes how to use jsp to implement ajax value passing in checkbox. Share it with you for your reference. The specific analysis is as follows:

Today, I want to use ajax to upload all the selected chekbox values to the backend for processing. However, when receiving values in the backend, I am in trouble, the request has no value because it has not been redirected.

Check and find the solution as follows:

Page code:
Copy codeThe Code is as follows: <input type = "checkbox" name = "atitle" value = "historical places of interest"> <label> historical places of interest </label>
<Input type = "checkbox" name = "atitle" value = "Southern Story"> <label> Southern story </label>
<Input type = "checkbox" name = "atitle" value = "workplace Story"> <label> Workplace story </label>
<Input type = "checkbox" name = "atitle" value = "emotional story"> <label> emotional story </label>
<Input type = "chec <A onClick =" check (); return false; "> submit </A>
<Script type = "text/javascript">
Function check (){
Var chk_value = [];
$ ('Input [name = atitle]: checked'). each (function (){
Chk_value.push ($ (this). val ());
});
// Chk_value = [historical places of interest, southern stories, workplace stories, emotional stories, legend puzzles]
// Chk_value should be like this.
$. Ajax ({
Type: "post ",
Url: convertURL ('up-ajx. jsp '),
// Data: {atitle: $ ('input [name = atitle] '). val ()},
// If this is the case, it can be transmitted normally, but it can only be the first value.
Data: 'atitle = '+ chkvalue,
// This does not seem to work. Now the problem is how atitle waits for multiple values at the same time.
// The up-ajx.jsp is obtained through Request. Form ("atitle"). can be directly used jsp can be normal operation.
DataType: "json ",
Error: function () {alert ('error. You have not selected the option. ');},
Success: function (msg ){
Alert (msg)
}
});
}
</Script>

I hope this article will help you with jsp-based Ajax programming.

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.