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.