I want to send PUT request with using Ajax. I send request with necessary information: newNavigation.
PUT request:
var newNavigation;
var newInputNavigation = document.getElementById('newInputNavigation');
newNavigation = newInputNavigation.value;
function editNavigation() {
var prefix = '/airline/';
$.ajax({
type: 'PUT',
url: prefix +'flights/' + idAction.replace('edit',''),
data: {
navigation: newNavigation
},
success: function(receive) {
$("#adminTable").empty();
$("#informationP").replaceWith(receive);
$("#hiddenLi").removeAttr('style');
},
error: function() {
alert('Error edited flight');
}
});
}
Controller:
private final String prefix = "/airline/";
@RequestMapping(value = prefix + "/flights/{id}", method = RequestMethod.PUT)
@ResponseBody
public String updateFlight(@PathVariable("id") String id, @RequestParam("navigation") String navigation) {
String returnText = "Flight edited successful";
String str1 = navigation;
String str2 = id;
return returnText;
}
Error:
PUT http://localhost:8080/airline/flights/11 400 ()
Questions:
How send PUT request with necessary data(newNavigation)?
How get data(newNavigation) in Spring controller?
EDIT:
Added NavigationDTO:
public class NavigationDTO implements Serializable{
public String navigation;
public NavigationDTO() {
super();
}
}
Changed controller:
@RequestMapping(value = prefix + "/flights/{id}", method = RequestMethod.PUT)
@ResponseBody
public String updateFlight(@PathVariable("id") String id, @RequestBody NavigationDTO navigation) {
String returnText = "Flight edited successful";
String str1 = navigation.navigation;
String str2 = id;
return returnText;
}
Error:
PUT http://localhost:8080/airline/flights/8 415 ()