我正在尝试从 angularjs 中的 jsonp 错误回调中获取响应消息,但响应数据未定义。我用 409 http 代码返回响应。如果直接在浏览器中打开 jsonp url,它会显示“angular.callbacks._0({"message":"Reset link is wrong"})”,但我无法在错误回调中收到此消息。我究竟做错了什么?
// Extend angular app for api requests
app.factory('User', function($http) {
var User = function(data) {
angular.extend(this, data);
};
// Send link for password reset to entered email
User.reset_password = function() {
return $http.jsonp(jsonp_url + 'user/reset_pass?_method=post&user_key=' + user_key + '&callback=JSON_CALLBACK');
};
return User;
});
app.controller('ResetPasswordController', function ResetPasswordController($scope, User){
$scope.submit = function() {
var response = User.reset_password();
response.then(function(data){
//Success callback
}, function(data){
// Error callback
console.log(data) // Output: {config : {...}, data: undefined}
});
}
});