Reputation: 5319
Hi i'm sending a integer array to my spring mvc controller method.When it is passed the data is getting to controller and functionality is working good. But after the function the controller will send some response to client side, on client side the response data goes to error function and showing
Uncaught SyntaxError: Unexpected token d
$.ajax({
type : 'GET',
dataType : 'json',
url : 'deleteTeacherSelectedNotes.html',
data : ({
notes : JSON.stringify(noteArray)
}),
success : function(responseData) {
stopPreloader();
},
error: function (response) {
var r = jQuery.parseJSON(response.responseText);
console.log("Message: " + r.Message);
console.log("StackTrace: " + r.StackTrace);
console.log("ExceptionType: " + r.ExceptionType);
}
});
@RequestMapping(value = "/deleteTeacherSelectedNotes.html", method = RequestMethod.GET)
@ResponseBody
public boolean deleteTeacherSelectedNotes(@RequestParam("notes")String notes) throws JSONException{
JSONArray arrJson = new JSONArray(notes);
for (int i = 0; i < arrJson.length(); i++) {
String x = arrJson.getString(i);
noteService.deleteNote(Integer.parseInt(x));
}
return false;
}
Upvotes: 1
Views: 3247
Reputation: 581
Try Changing data type to JSON
$.ajax({
type : 'GET',
dataType : 'JSON',
url : 'deleteTeacherSelectedNotes.html',
data : ({
notes : JSON.stringify(noteArray)
}),
success : function(responseData) {
stopPreloader();
},
error: function (response) {
var r = jQuery.parseJSON(response.responseText);
console.log("Message: " + r.Message);
console.log("StackTrace: " + r.StackTrace);
console.log("ExceptionType: " + r.ExceptionType);
}
});
Upvotes: 1