I have a controller class which has below mapping and I'm trying to call this with ajax.
@RequestMapping(value = "/jobs", method = RequestMethod.POST, headers = "Accept=*/*")
@ResponseBody
public String associate(@ModelAttribute ("job") Job job, @RequestParam(value="ips") String[] ips) {
logger.debug("associate: No of IP Ranges: {} ", ips.length);
logger.debug("associate: jobSchedule: {} " , job.getScanId());
}
Jquery Ajax call as below:
$.ajax({
type: 'POST',
url: urlstr,
data : {job:job ,ips: ipIds.toString()}
success: function(data, textStatus, jqXHR) {
if(data != ""){
if(data != ""){
alert(data);
location = ctx + '/rest/settings';
}
}
},
error: function(jqXHR, textStatus, errorThrown) {
alert('There was an error in scheduling.' + errorThrown );
}
});
It is able to pring ips length but job.getScanId() returns null. But when I alert in the jsp , it prints the scan ids from my json job object.
I'm not knowing what mistake I'm making. I think I'm right in controller part but I don't know whether I'm passing job object and string array correctly. Any pointers?