The example of this article describes the AJAX implementation of the checkbox in the JSP transfer value usage. Share to everyone for your reference. The specific analysis is as follows:
Today, I want to use Ajax to all the selected Chekbox values are uploaded to the background to do a deal, but in the background to receive the value of the time, I encountered trouble, thought did not jump so request is no value.
Check it out, find the solution, as follows
Page code:
Copy Code code as follows:
<input type= "checkbox" Name= "Atitle" value= "Historical sites" ><label> Historical monuments </label>
<input type= "checkbox" Name= "Atitle" value= "South Story" ><label> South story </label>
<input type= "checkbox" Name= "Atitle" value= "career Story" ><label> career story </label>
<input type= "checkbox" Name= "Atitle" value= "emotion Story" ><label> Emotion 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 Sites, Southern stories, career stories, emotional stories, legends puzzle
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 only the first value.
Data: ' atitle= ' +chkvalue,
This seems to be no, now the problem is out here, atitle how to wait for multiple values at the same time.
Up-ajx.jsp is obtained by Request.Form ("Atitle"). The direct use of the JSP can be a normal operation.
DataType: "JSON",
Error:function () {alert (' Error, you do not have a selection option. ');},
Success:function (msg) {
Alert (msg)
}
});
}
</script>
I hope this article will help you with the AJAX program design based on JSP.