Note that there are some explanatory texts on larger screens.

plurals
  1. POsending javascript object arrays as parameters to controller
    primarykey
    data
    text
    <p><strike>Question is pretty self explanatory. I want to send 2 different arrays of objects through a POST form without ajax to my controller.</strike></p> <p>I changed my question to using ajax and using a get request due to the size of the params. Currently getting a 400 (Bad Request). I have no idea why. Please take a look...</p> <p>I have objects:</p> <pre><code>var phone = {phoneId:"", phoneNumber:"", phoneType:""}; var schedule = {scheduleId:"", time:"", day:""}; </code></pre> <p>Which I place into a javascript arrays:</p> <pre><code>var phones = [phone1, phone2, phone3]; var schedules = [schedule1, schedule2]; </code></pre> <p>and I use ajax to send:</p> <pre><code>var data = { index: id, schedules: schedules, phones: phones } var url = "/myController/myUrl" $.getJSON(url, data, function(result){ if(result.ok){ $('#messageAlertSuccess').show(); } else { $('#messageAlertError').show(); } }); </code></pre> <p>I created wrapping classes to map them like so:</p> <pre><code>public class PhoneWrapper(){ private String phoneId; private String phoneNumber; private String phoneType; } </code></pre> <p>And of course the scheduleWrapper follows the same convention. </p> <p>Here's the method in my controller:</p> <pre><code>@ResponseBody @RequestMapping(value="/myUrl", method=RequestMethod.GET) public Result doSomething(@RequestParam("index") int index, @RequestParam("phones") Set&lt;PhoneWrapper&gt; phoneWrappers, @RequestParam("schedules") Set&lt;ScheduleWrapper&gt; scheduleWrappers, Model model, HttpSession session){ //do stuff here. } </code></pre> <p>I am currently getting a 400. So what's wrong?</p> <hr> <p>Update: here's the url that the .getJSON jquery method is building:</p> <pre><code>http://localhost:8080/myApp/myController/myUrl?index=9&amp;schedules%5B0%5D%5BscheduleId%5D=1&amp;schedules%5B0%5D%5BfromDay%5D=Monday&amp;schedules%5B0%5D%5BtoDay%5D=Friday&amp;schedules%5B0%5D%5BfromTime%5D=08%3A30%3A00&amp;schedules%5B0%5D%5BtoTime%5D=16%3A00%3A00&amp;schedules%5B1%5D%5BscheduleId%5D=5&amp;schedules%5B1%5D%5BfromDay%5D=Saturday&amp;schedules%5B1%5D%5BtoDay%5D=Monday&amp;schedules%5B1%5D%5BfromTime%5D=09%3A00%3A00&amp;schedules%5B1%5D%5BtoTime%5D=13%3A00%3A00&amp;phones%5B0%5D%5BphoneId%5D=6&amp;phones%5B0%5D%5BphoneNumber%5D=787-788-1111&amp;phones%5B0%5D%5BphoneType%5D=PHONE&amp;phones%5B1%5D%5BphoneId%5D=106&amp;phones%5B1%5D%5BphoneNumber%5D=787-795-4095&amp;phones%5B1%5D%5BphoneType%5D=FAX </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload