Well basically just trying to implement some ajax into my spring web application. For testing purposes I have tried writing some code just to retrieve 'user' information based on their personal 'id' values when they press a link/button. I am assuming that it is a Server side error, that something is wrong with my controller, although I am not entirely sure and need help getting this to work. This is my current JSP page just for testing:
$(document).ready(function(){
$('.ajax').click(function(e){
e.preventDefault();
$.ajax({
url:"http://localhost:8080/SDP_v1.7/ajax",
type: 'GET',
dataType:'json',
contentType: 'application/json',
mimeType: 'application/json',
succes: function(user){
alert(user.id + " + " + user.username);
},
error:function(user,status,er) {
alert("error: "+user+" status: "+status+" er:"+er);
}
});
});
});
This is my Controller class:
@RequestMapping("/viewUser")
public String updateUser(Model model, @RequestParam(value = "id", required = false) Integer id) {
User user = usersService.getUser(id);
model.addAttribute("user", user);
return "settings";
}
@RequestMapping(value = "/ajax", method = RequestMethod.GET)
public @ResponseBody User getUser(@PathVariable Integer id) {
return usersService.getUser(id);
}
This is my error popping up in the console:
GET http://localhost:8080/SDP_v1.7/ajax 403 (Forbidden) jquery.js:5
send jquery.js:5
x.extend.ajax jquery.js:5
(anonymous function) users:106
x.event.dispatch jquery.js:4
v.handle
Essentially, I aiming to loading each user's information into a pop-up modal with a form. Although I have to get this step working first. Thanks