0

我有一个 jsp 页面,它有一个 html 表单,它有 3 个隐藏字段、1 个选择框和一个包含 10 个复选框和一个提交按钮的 div。表单的 action 属性中没有设置此表单的操作页面。表单是使用 ajax 提交的。表单要么在选择框的 chage 事件上提交给 servlet A,要么在提交按钮的单击事件上提交给 servlet B。

每当从选择框中选择一个值时,就会使用 ajax 提交表单,并且包含与复选框关联的用户名列表的 ajax 响应会在 div 中呈现,而无需刷新页面。这部分工作正常。

每当单击提交按钮时,都会使用 ajax 提交表单,如果选择了任何复选框,则复选框的值将存储在会话中。问题就在这里。每当第一次呈现 Jsp 页面时,如果我们选择了一些复选框并单击了提交按钮,那么上面解释的功能就可以正常工作。但是,在呈现 jsp 页面并选择选择框选项并呈现包含复选框的 ajax 响应后,如果我选择了几个复选框并单击提交按钮,则在 Servlet BI 中仅获取隐藏字段和选择框的值,但值的复选框没有收到 servlet B。

我想请教专家这个问题背后的原因以及解决方案是什么。

以下是通过单击提交按钮执行的 jquery 代码。

$("#idbtnsubmituser").click(function(){
    //alert("this is test1");

    //get the form data and then serialize that
    dataString = $("#userlistrequestform").serialize();  
    /*
    As per my understanding the above code line is not getting the selected     checkboxes value. i.e. the serialize function can not 
detect the check boxes rendered by ajax response on event of select box change event.
    */
    $.ajax({
     type: "POST",
     url: "CutUser",
     data: dataString,
     //dataType: "json",

    //if received a response from the server
    success: function( data, textStatus, jqXHR) {
        $("#idmoveuserdiv").html(data);
    },

    //If there was no resonse from the server
    error: function(jqXHR, textStatus, errorThrown){
         console.log("Something really bad happened " + textStatus);
          $("#ajaxuserListResponse").html(jqXHR.responseText);
    },

    //capture the request before it was sent to server
    beforeSend: function(jqXHR, settings){
        $('#userlistpageselect').attr("disabled", true);
    },

    //this is called after the response or error functions are finsihed
    //so that we can take some action
    complete: function(jqXHR, textStatus){
        //enable the button 
        $('#userlistpageselect').attr("disabled", false);
        $('.checkuser').attr("checked",false);
    }
});
});

请朋友们指导我解决这个问题。

感谢您!

4

0 回答 0