1
サーバーにAjax要求を送信しましたが、サーバーが応答しません。エラー415(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