简体   繁体   中英

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); 
      }
    });

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM