1

How to send array to ajax request.Here is my code skills is array

var url= "/ajax/gDirectory/saveskills.htm";
                 $.ajax({
                    type: "POST",
                    data: {skills:skills},
                    url: url,
                    async: true,
                    success :skillsUI
                  }); 

Spring Controller How to get parameter in controller

 @RequestMapping(value="/ajax/gDirectory/saveskills.htm" ,method=RequestMethod.POST)
        public @ResponseBody String saveskills(HttpServletRequest request,@RequestParam String skills) {}
  • how that skill object looks in js? – Neha Jan 15 '14 at 06:22
  • It's normal array.I have array so if there is another way then let me know..Its not json string –  Jan 15 '14 at 06:28
  • U can convert array to json string and pass it, look this thread - http://stackoverflow.com/questions/713884/convert-js-array-to-json-object-for-use-with-jquery-ajax – Neha Jan 15 '14 at 06:38

1 Answers1

0

You can use the @RequestBody annotation instead @RequestParam.

Let's suppose that you have a class called "Skill" that has the same attributes that your "skill" json object has.

@RequestMapping(value="/ajax/gDirectory/saveskills.htm" ,method=RequestMethod.POST)
        public @ResponseBody String saveskills(HttpServletRequest request, @RequestBody List<Skill> skills) {}
Roman
  • 313
  • 3
  • 9