我正在尝试执行ajax调用,但不断收到错误415 - 不支持的媒体类型。我甚至尝试设置标题Content-Type : application/json
,但它仍然无效。
function addTaskInSheet(taskToUpdate){
var accessToken = $rootScope.accessToken;
var groupId = $rootScope.groupId;
var url = "https://spreadsheets.google.com/feeds/list/" + groupId + "/od6/private/full" ;
var updatedTask = {};
$.ajax({
url:url,
type: 'POST',
async: false,
data: JSON.stringify(taskToUpdate),
dataType: 'json',
contentType: 'application/json',
crossDomain: true,
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xhr.setRequestHeader('Content-Type','application/json');
},
success: function (response) {
updatedTask = response;
console.log(updatedTask);
}, error: function (response) {
console.log(response);
}
});
return updatedTask;
}
答案 0 :(得分:0)
尝试在ajax Accept
方法中添加beforeSend
标题,如下:
..
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xhr.setRequestHeader('Accept','application/json');
xhr.setRequestHeader('Content-Type','application/json');
},
..