1

Hello guys i having an error status 404 basically i am trying to go into another endpoint but receving error code:

There was an unexpected error (type=Bad Request, status=400).
Required request body content is missing: org.springframework.web.method.HandlerMethod$HandlerMethodParameter@2c553a08

$.ajax({
            type: 'post',
            url: 'guest/search',

            data: JSON.stringify(formData),
            contentType: 'application/json',
            success: function(dataRecieved){
                var dataRecieved= $.trim(dataRecieved);
                //console.log(dataRecieved);
                if(dataRecieved === 'true'){
                    $("#statusPlaceholder").html("Great rooms are available");
                    window.location.href="/guestReservation";
                }else{
                    $("#statusPlaceholder").html("Sorry. Rooms are not available. Please try again").show().fadeOut(3000).css("color","red");
                }
            }

        });

Spring mapping:

 @RequestMapping(value = "/guestReservation", method = RequestMethod.GET)
    public String createGuest(@RequestBody Guest guest){
        // return new ResponseEntity<>(guestservice.create(gst), HttpStatus.OK);
        return "guestReservation";
    }

My question is how do i add a request body in window.location.href

  • 1
    You need to POST to `/guestReservation` rather than GET (which location.href does). Edit: Which contradicts your Spring mapping... – freedomn-m Dec 15 '15 at 10:10
  • Possible duplicate of [HTTP GET with request body](http://stackoverflow.com/questions/978061/http-get-with-request-body) – freedomn-m Dec 15 '15 at 10:12
  • More likely duplicate: http://stackoverflow.com/questions/2367979/pass-post-data-with-window-location-href Summary: Using window.location.href it's not possible to send a POST request. – freedomn-m Dec 15 '15 at 10:13
  • @freedomn-m so how do i solve the problem – kendra SMITH Dec 15 '15 at 10:18
  • @freedomn-m im not sending a post a request I'm trying to go to another page. Please could u assist – kendra SMITH Dec 15 '15 at 10:39
  • You could change your Spring mapping to accept the parameters on the url query string (ie just remove @RequestBody) – freedomn-m Dec 15 '15 at 10:56
  • @freedomn-m I'm going to a page that needs to make a reservation so i retrieve the data from the url mapping /guestReservation thats why i added the RequestBody. – kendra SMITH Dec 15 '15 at 11:15
  • "retrieve the data from the url" "RequestBody" - these are not the same thing. `location.href="/guestReservation?reservationId=x&guestName=y"` would be passing it on the url. – freedomn-m Dec 15 '15 at 21:35
  • @freedomn-m thanks for the help i actually solved. I really appreciate your patience and comments. – kendra SMITH Dec 16 '15 at 01:17

0 Answers0