我处理的todoist API(https://developer.todoist.com/)和我正在为某些数据与这个jQuery的AJAX GET请求:如何在jQuery ajax调用上将JSON响应解析为JSONP?
var url = "https://todoist.com/API/v7/sync";
var data = {
'token' : token,
'resource_types' : '["all"]',
};
$.ajax({
url: url,
data: data,
type: 'GET',
dataType: 'jsonp',
success: function(response) {
console.log(response);
},
error: function(response) {
console.log('error');
},
});
现在,当我得到的回应,我得到的错误
Unexpected token :
为什么?因为根据(https://stackoverflow.com/a/7941973/2724978)jQuery期待jsonp格式的响应,但它返回json。
我已经研究了如何解决这个问题,响应将是:“以jsonp格式返回数据”..好。它是一个外部API,它们不提供JSONP中的数据。有没有办法我可以覆盖返回的函数并解析这个JSON数据呢?
'token'定义?链接文档建议使用POST请求_“同步API请求应在HTTP POST(application/x-www-form-urlencoded)中进行。包含错误的同步API响应将以JSON返回。 – guest271314
它被定义,是 – raphadko