jsp Implements ajax Value Transfer Instances for checkbox

  • 2021-06-28 13:40:06
  • OfStack

This article gives an example of ajax value transfer usage for jsp to implement checkbox.Share it for your reference.Specific analysis is as follows:

Today, I want to use ajax to send all the selected chekbox values to the background for a processing, but when I receive the values in the background, I have trouble thinking that there is no value in request without a jump.

Check it out and find the solution as follows

Page Code:

<input type="checkbox" name="atitle" value=" Historical Sites "><label> Historical Sites </label>
<input type="checkbox" name="atitle" value=" Southern Stories "><label> Southern Stories </label>
<input type="checkbox" name="atitle" value=" Work Story "><label> Work Story </label>
<input type="checkbox" name="atitle" value=" Emotional Stories "><label> Emotional Stories </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 , Work Story , Emotional Stories , Legend Solve Puzzle ]
 //chk_value It 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 first 1 Values .
 data:'atitle='+chkvalue,
 // That doesn't seem to work , Now the problem is here ,atitle How to Wait for Multiple Values at the Same Time .
 //up-ajx.jsp Here is through Request.Form("atitle") To get . Direct use of fruits jsp Is operational .
   dataType: "json",
   error: function(){alert(' Error, you have no choice. ');},
   success: function(msg){
alert(msg)
}
});
}
</script>

I hope that the description in this paper will be helpful to everyone's Ajax program design based on jsp.


Related articles: