我有一个不向服务器发送数据的ajax put请求
handleUpdate(meal) {
console.log(meal)
var meals = this.state.meals;
$.ajax({
url: `api/v2/meals/${meal.id}`,
type: 'PUT',
date: {name: meal.name, calories: meal.calories, meal_time: meal.meal_time, meal_date: meal.meal_date},
headers: window.Auth.retrieveData('authHeaders'),
success: (new_meal) => {
this.setState({
meals: meals.map(meal => meal.id === new_meal.id ? new_meal : meal)
})
},
error: (response) => {
console.log(response);
}
});
我究竟做错了什么?
最佳答案
希望您在下面有一个typo
而不是data
,而您有date
。请看下面的评论
handleUpdate(meal) {
console.log(meal)
var meals = this.state.meals;
$.ajax({
url: 'api/v2/meals/${meal.id}',
type: 'PUT',
// The below should be 'data'
date: {name: meal.name, calories: meal.calories, meal_time: meal.meal_time, meal_date: meal.meal_date},
headers: window.Auth.retrieveData('authHeaders'),
success: (new_meal) => {
this.setState({
meals: meals.map(meal => meal.id === new_meal.id ? new_meal : meal)
})
},
error: (response) => {
console.log(response);
}
});
关于jquery - jQuery Ajax PUT请求未将数据发送到服务器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40601235/