Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
选中多个复选框&;jquery&;春季mvc_Jquery_Ajax_Spring - Fatal编程技术网

选中多个复选框&;jquery&;春季mvc

选中多个复选框&;jquery&;春季mvc,jquery,ajax,spring,Jquery,Ajax,Spring,我尝试勾选多个复选框,并不是全部使用Ajax调用。它工作正常,但当我取消勾选它们时,只有一个复选框未选中,其他复选框将再次选中 用于检查和取消检查的Ajax调用: $(function(){ $('input[type=checkbox]').bind("change",function(){ if($(":checkbox[path='description']:checked").length > 0 ){ $.ajax({ type: 'POST',

我尝试勾选多个复选框,并不是全部使用Ajax调用。它工作正常,但当我取消勾选它们时,只有一个复选框未选中,其他复选框将再次选中

用于检查和取消检查的Ajax调用:

   $(function(){
$('input[type=checkbox]').bind("change",function(){ 

if($(":checkbox[path='description']:checked").length > 0 ){
    $.ajax({
        type: 'POST',
        url: 'check.html',
        data: { "id": $(this).attr('cid')},
        success: function(data){
        }

    });
}

else{

    $.ajax({
        type: 'POST',
        url: 'uncheck.html',
        data: { "id": $(this).attr('cid')},
        success: function(data){
        }
    });


}

});

 });
html部分,用于检查点的循环:

        <c:forEach var = "c" items = "${planid.checkpoints}" varStatus="status">

                         <c:if  test = "${c.st eq s.name and c.rw eq r.name}">

                         <p><input  cid="${c.id}" class= "case" path="description" type="checkbox" value="${c.description}"   />
                         <c:out  value = "${c.description}"></c:out>

                        <security:authorize access="hasRole('admin')">                              
                        <a href="/gefp/jsp/Edit.html?id=${c.id}">[Edit]</a>
                        </security:authorize>

                        </p>

                    </c:if>

                 </c:forEach>


在控制器中:

    @RequestMapping("/jsp/check.html") 
      @ResponseBody
      public  ResponseEntity<String> check(@RequestParam Long id,     HttpSession session){

        String u=SecurityUtils.getUsername();
         User user=userDao.getUser(u).get(0);        
         user.getId();

         Checkpoint cp = userDao.getCheckpoint(id);         

         user.getCheckpoints().add(cp);
         userDao.saveUser(user);

        return new ResponseEntity<String>( HttpStatus.OK );

    }



    @RequestMapping("/jsp/uncheck.html") 
    @ResponseStatus(HttpStatus.OK)
    public void uncheck(@RequestParam Long id){   

         String u=SecurityUtils.getUsername();
         User user=userDao.getUser(u).get(0);        
         user.getId();

        Checkpoint cp = userDao.getCheckpoint(id);
        user.getCheckpoints().remove(cp);
        userDao.saveUser(user);
    }
@RequestMapping(“/jsp/check.html”)
@应答器
公共响应性检查(@RequestParam Long id,HttpSession会话){
字符串u=SecurityUtils.getUsername();
User User=userDao.getUser(u.get)(0);
getId();
Checkpoint cp=userDao.getCheckpoint(id);
user.getCheckpoints().add(cp);
userDao.saveUser(用户);
返回新的响应状态(HttpStatus.OK);
}
@RequestMapping(“/jsp/uncheck.html”)
@ResponseStatus(HttpStatus.OK)
public void取消选中(@RequestParam Long id){
字符串u=SecurityUtils.getUsername();
User User=userDao.getUser(u.get)(0);
getId();
Checkpoint cp=userDao.getCheckpoint(id);
user.getCheckpoints().remove(cp);
userDao.saveUser(用户);
}
我通过

$(function(){
$('input[type=checkbox]').change(function(){ 
    var checked = $(this).is(':checked');

if(checked){
    $.ajax({
        type: 'POST',
        url: 'check.html',
        data: { "id": $(this).attr('cid')},
        success: function(data){
        }

    });
}

else{

    $.ajax({
        type: 'POST',
        url: 'uncheck.html',
        data: { "id": $(this).attr('cid')},
        success: function(data){
        }
    });


}

});

 });

您的ajax请求要求每个请求有一个id,或者所有已检查的id都应该在一个请求中发送?取消选中调用应该在什么时候发送呢happen@Arun约翰。编辑它。你能检查一下吗