Sowmya
Sowmya

Reputation: 26979

JSON data 400 Bad request Error

I have JSON data sending to server. When I submit the for it is printing the data in console but not sending to the server.

It gives the following error

POST http://localhost:8080/rest/review/createReview 400 (Bad Request) 

Here is my code

var promise = jQuery.ajax({
      url: 'http://localhost:8080/rest/review/createReview',
      type: 'POST',
      data: '{myReview: myReview}',
      dataType: "text",
      contentType: "application/json",
      success: function (data) {
           console.log("Request successful", data);
      },
      error: function (data) {
          console.log("Request failed", data); 
      }
    });

Upvotes: 1

Views: 2164

Answers (1)

Mike Brant
Mike Brant

Reputation: 71384

It may be that your data is not valid JSON. Try:

data: JSON.stringify({myReview: myReview})

Upvotes: 2

Related Questions