Spring MVC Not getting back any results with ajax request

3078 views javascript

I want to get data about my user from ajax request. But it never logs anything, which means it never reaches to success part of ajax request.

This is my controller

@RequestMapping(value = "/api/profile")
public class ProfilController {

public UserService userService;

@RequestMapping(value = "/show/{username}", method = RequestMethod.GET)
public ResponseEntity<UserDTO> showData(@PathVariable String username) {
    User u = userService.findByUsername(username);
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    return new ResponseEntity<>(new UserDTO(u), HttpStatus.OK);

And this is my java script file.

$(document).ready(function() {
var usrnm = localStorage.getItem('loggedIn');

  url: "http://localhost:8080/api/user/login/check/"+usrnm,
  type: "GET",
  headers: {"Authorization": localStorage.jwt},
  success: function(data) {

    url: "http://localhost:8080/api/profile/show/"+usrnm,
    type: "GET",
    success: function(data) {
        console.log('This part is not executed');

I am new to Spring, actually I am new to programming so sorry if this question is not well formatted

answered question

request & response are nothing? show me network status.

1 Answer


You may have an error in the showData function. You should do the following: @PathVariable("username") String username

posted this

Have an answer?


Please login first before posting an answer.