4

In my application I need to pass an array of parameters form client side to server side. I tried the following code but its not working.I need to get data from checkbox list and pass it to server side. My code for the client side

$(".add").click(function(){

    monitoring.length=0;
    nonMonitoring.length=0;
    $('.modal-body input:checked').each(function() {
        monitoring.push($(this).val());
        });

    $('.addkeywords input:checked').each(function() {
        nonMonitoring.push($(this).val());
        });


//  alert(monitoring[2]+ " " + nonMonitoring[2]);
    var monitoringLength=monitoring.length;
    var nonMonitoringLength=nonMonitoring.length;


    $.ajax({
            type : "GET",
            url : '/rest/my/rest/mysql/controller',
            data : {
                monitoringLength: monitoringLength,
                nonMonitoringLength: nonMonitoringLength,
                monitoring : monitoring,
                nonMonitoring: nonMonitoring,


            },
            success : function(data) {

            //  var keywordsList=data
                //console.log(keywordsList);
            //  htm = "" ;

                if(data=='success'){
                    //  loadChannels();
                    location.reload();
                    }else{
                alert("failed to upload");

                }


            }


});



})

My code for the server side.

@RequestMapping("/rest/my/rest/mysql/controller")

    public void monitorKeywords(@RequestParam(value="monitoringLength",required=true)int monitoringLength,@RequestParam(value="nonMonitoringLength",required=true)int nonMonitoringLength,@RequestParam(value="monitoring",required=true)List<String> monitoring,@RequestParam(value="nonMonitoring",required=true)List<String> nonMonitoring){
        System.out.println("MonitoringLength =>" +monitoringLength);
        System.out.println("NonMonitoringLength=>" +nonMonitoringLength);
        System.out.println("Monitoring=>" +monitoring);
        System.out.println("Monitoring=>" +nonMonitoring);

Somehow this is not working.What is the error in this? Please help

1 Answer 1

3

In Request parameter change List to array

i.e.

@RequestParam(value="monitoring",required=true) String[] monitoring, @RequestParam(value="nonMonitoring",required=true) String[] nonMonitoring
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.