1
我發送Ajax請求到我的服務器,但服務器沒有得到響應。錯誤415與Ajax請求(Ajax,Spring)
PUT請求:
function editNavigation() {
var flight={
id:idAction.replace('edit',''),
navigation:newNavigation
};
console.log(flight);
var prefix = '/airline/';
$.ajax({
type: 'PUT',
url: prefix +'flights/' + idAction.replace('edit',''),
data: JSON.stringify(flight),
headers:{contentType: "application/json"},
success: function(receive) {
$("#adminTable").empty();
$("#informationP").replaceWith(receive);
$("#hiddenLi").removeAttr('style');
},
error: function() {
alert('Error edited flight');
}
});
}
控制器:
@RequestMapping(value = prefix + "/flights/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public String updateFlight(@PathVariable("id") String id, @RequestBody FlightDto flightDto) {
String returnText = "Flight edited successful";
String str1 = flightDto.getNavigation();
logger.info(str1);
String str2 = id;
logger.info(str2);
return returnText;
}
瀏覽器控制檯:
Object {id: "5", navigation: "sdf"}
PUT http://localhost:8080/airline/flights/5 415()
我爲什麼GE t錯誤415? 爲什麼我的控制器不發送響應?
您是否嘗試過檢查瀏覽器的網絡標籤中的回覆?按F12鍵並檢查它,向我們提供更多信息 – BrunoDM
請驗證您從網絡選項卡發送的請求的「Content-Type」標頭。 –
@Pete你是什麼意思? – studentST