I am facing an issue with submitting JSON data through jQuery AJAX. I have searched for similar problems online, but none of the solutions seem to be working for me.
$.ajax({
type : "POST",
contentType : "application/json",
url : "save-routes",
data : JSON.stringify(routeObject),
dataType : 'json',
timeout : 100000,
success : function(status) {
console.log("SUCCESS ADDING ROUTE DATA");
return status;
},
error : function(e) {
console.log("ERROR WHILE ADDING ROUTE DATA");
return false;
},
done : function(e) {
console.log("DONE");
//return true;
}
});
routeObejct Json format:
{name:"value", data:["value1","value2"...]}
spring controller:
@JsonView(Views.Public.class)
@RequestMapping(value = "/save-routes", method = RequestMethod.POST)
public @ResponseBody boolean loadRoutes(@RequestBody Route route) {
//codes
return status;
}
I am consistently receiving this error message:
POST http://localhost:8181/SYBusWebApp/save-route 400 Bad Request 6ms
Route Class:
public class Route {
@JsonView(Views.Public.class)
private String name;
@JsonView(Views.Public.class)
private ArrayList<stop> routeStops;
private String updatedRouteName;
private ArrayList<String> addedRouteStopNames;
//getters and setters
}
Stop Class:
public class Stop {
@JsonView(Views.Public.class)
private String name;
@JsonView(Views.Public.class)
private float latitude;
@JsonView(Views.Public.class)
private float longitude;
private String updatedName;
//getters and setters
}