Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to pass long array from jquery load to spring controller. I have passed string variable succefully but not the array.

javascript:

function ModuleMemberCheckboxPassIds(){
     var memberUserIds = [];
     var memberNames = [];
     $('.membercheckbox:checked').each(function(i){      
         memberUserIds[i] = $(this).val();
     });
     alert(memberUserIds.length);
     $( "#onetextarea" ).load('/assign_task', {"memberUserIds":memberUserIds,  "testdata": "test", });   
}

spring controller:

@RequestMapping(value="/assign_task")
    public String viewAssignTask(Model model, String testdata, HttpServletRequest request){

        if(request.getAttribute("memberUserIds")==null) System.out.println("null"); else System.out.println("not null"); //returns null

        System.out.println("test: " + testdata);//returns a value

        model.addAttribute("transferVO", new TransferVO());
        return "module/view-members-checkbox";
    }

In viewAssignTask method I was able to read tesdata variable that was sent from jquery. But memberUserIds returns null

please help

share|improve this question
add comment

2 Answers

Are you expecting an incoming JSON object on the server? If so you could try using $.ajax instead of $.load:

var data={"memberUserIds":memberUserIds,"testdata": "test"};

$.ajax({
    url: '/assign_task',
    type: 'GET',
    data: JSON.stringify(data),
    contentType: 'application/json',
    success: function(html) {
        $("#onetextarea").html(html);
    }
}); 
share|improve this answer
    
GET did not work, i had to change it to post. I don't know why but I had to write this data: JSON.stringify(eval({"memberUserIds":memberUserIds ,"testdata":"test"})), –  user510783 May 19 '13 at 19:42
    
if you are sending JSON, you have to JSON.stringify(data). Sorry fotgot to do that in my example. Try that with GET. –  panpiper May 19 '13 at 19:46
add comment

You can use:

request.getParameterValues("memberUserIds");

for getting multivalued Parameters.

Otherwise:

One suggestion you want to use features of Spring MVC then code should be :

RequestMapping(value="/assign_task")
    public String viewAssignTask(Model model, String testdata,@RequestParam String [] memberUserIds, @RequestParam String testData){
//Your Code
 }
share|improve this answer
    
request.getParameterValues("memberUserIds"); was still showing null. I don't get it using @RequestParam was not working. Call was not directed to this controller. @RequestMapping(value="/assign_task") public String viewAssignTask(Model model,@RequestParam String[] memberUserIds,@RequestParam String testdata){ ...} Javascript call: $( "#onetextarea" ).load('/hamdan/module/assign_task', {"memberUserIds":memberUserIds, "testdata": "test", }); –  user510783 May 18 '13 at 12:33
    
can you send me error message –  Manav Dewan May 18 '13 at 13:04
    
there is no error message. Code is fine. I think request couldn't find which contoller and path the request should be dispatched –  user510783 May 18 '13 at 13:43
    
may be URL of the request is wrong. so try to add absolute path load('localhost:8080/myapp_/assign_task' –  Manav Dewan May 18 '13 at 14:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.