How to parse JSON object at jsp

I wauld parse JSON object(List) which the i pass from controller. I want to convert my JSON object in html, but I want to extract each parameter separately.

@JsonView(View.Public.class)
@RequestMapping(value = "/updatecomments", method = RequestMethod.GET)
@ResponseBody
public List<Commentary> updateCommentary(@RequestParam int idEvent) {
    System.out.println("updatecomm: " + idEvent);
    Event event = eventService.findById(idEvent);
    List<Commentary> comments = event.getComments();
    return comments;
}

when i parse with this function it’s work:


    function updateComments() {
        $.ajax({
            url : "/updatecomments",
            method : 'GET',
            data : {
                idEvent: ${event.getId()},
            },
            dataType : 'json',
            success : function(results){
                alert("succes");
                var json = "

Ajax Response

"
                    + JSON.stringify(results, null, 4) + "

";
$('#feedback').html(json);
}
});
};

but when i would parse with this code, it isn’t work:


    function updateComments() {
        $.ajax({
            url : "/updatecomments",
            method : 'GET',
            data : {
                idEvent: ${event.getId()},
            },
            dataType : 'json',
            success : function(results){
                alert("succes");

                
                    alert(${comment.description});
                    alert(1);
                
            }
        });
    };

This function also does not work

var comments = $.parseJSON(results);

What is my mistake?


Source: stackoverflow-javascript

Sending form from Angular JS to Spring

I have simple application AngularJS and Spring boot. I want to pass whole form pre-filled by user to my app and register . Usually I had no problems – was passing JSON obj with correct structure and presto. However here I just run in cricle.
The form payload is sent to controller, address mapping is correct , but java form content is empty

Payload sent to server:

{"userform":{"name":"a","surname":"a","email":"a@a.com","password":"a","confirmPassword":"a"}}

Here is my html:

There was a problem registering. Please try again.
<form role="form" name="userForm" ng-submit="register()">
<button type="submit" class="btn btn-primary">Submit</button>

Here java script

app.controller('register', function ($scope, $rootScope, $http) {
    $scope.formData = {};
    $scope.register = function () {
        $http.post('/api/register', {userform: $scope.formData}).then(
            function (resposne) {
                console.log("registered");
                console.log(response);
            },
            function (response) {
                console.log("Register error")
            }
        )
      }
});

And here controller:

@RestController
@RequestMapping("/api")
public class ApiController {

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public String register(@RequestBody RegisterForm userform) {
        System.out.println("name:" + userform.getName());
        System.out.println("surname:" + userform.getSurname());
        return "OK";
    }
}

and last but not least RegisterForm:

public class RegisterForm {
    private static final String NOT_BLANK_MESSAGE = "Cannot be blank";
    @NotBlank
    @Email(message = "Not email")
    private String email;

    @NotBlank(message = RegisterForm.NOT_BLANK_MESSAGE)
    private String name;

    @NotBlank(message = RegisterForm.NOT_BLANK_MESSAGE)
    private String surname;

    @NotBlank(message = RegisterForm.NOT_BLANK_MESSAGE)
    private String password;

    @NotBlank(message = RegisterForm.NOT_BLANK_MESSAGE)
    private String confirmpassword;

    /*-----GETTERS AND SETTERS HERE----*/
}


Source: stackoverflow-javascript