I would like to pass an array from javascript in web browser to a Spring MVC controller using AJAX
In javascript, I have
var a = [];
a[0] = 1;
a[1] =
Fully tested solution
$.ajax({
type : "POST",
url : "/myurl",
data : {
myArray: a //notice that "myArray" matches the value for @RequestParam
//on the Java side
},
success : function(response) {
// do something ...
},
error : function(e) {
alert('Error: ' + e);
}
});
@RequestMapping(value = "/save/", method = RequestMethod.POST)
public String controllerMethod(@RequestParam(value="myArray[]") List myArray){
System.out.println("My Array"+myArray.get(0));
return "";
}