postData: function (url, data) {
var deferred = Q.defer();
$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(data),
dataType: "json",
beforeSend: function (xhr, settings) {
xhr.setRequestHeader('Authorization', 'Bearer ' + window.access_token);
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
},
success: function (data, responseText, jqXHR) {
deferred.resolve(data, responseText, jqXHR);
},
error: function (e) {
deferred.reject(e);
}
});
return deferred.promise;
}
我不明白为什么我的请求会进入错误回调
答案 0 :(得分:2)
根据您要返回html的评论,您需要设置适当的mail("someone@example.com","My subject",$msg);
dataType
也会出错。您可以通过记录错误处理程序$.ajax
尝试更改
error: function (xhr, statusText, errorThrown)
要
dataType:'json'
或者删除该属性,因为jQuery将从内容类型标题中知道