Angular $ http.jsonp中未定义成功

时间:2014-04-21 21:40:36

标签: angularjs cordova

我在angular / phonegap应用中发出了$ http.jsonp请求。数据已成功传送到远程服务器,但我无法从角度应用程序中的成功函数获得响应。控制台告诉我,未定义成功。'

这是我的角度代码:

app.controller('mainControl' , function($scope , $http){
$scope.credentials = {username: '' , password: ''};

$scope.login = function(){
console.log($scope);

var url = "http://127.0.0.1:3000/endpoint?callback=JSON_CALLBACK";
var responsePromise = $http.jsonp(url, {params: {
  username:$scope.credentials.username,
  password:$scope.credentials.password
}});

responsePromise.success(function (data){
  console.log(data);
})
}

})

为了定义成功,我错过了一步吗?

1 个答案:

答案 0 :(得分:1)

我相信对于jsonp你必须使用处理承诺解析的.then方法:

responsePromise.then(function (data){
    //success things go here
    console.log(data);
}, function(data({
    //error things go here
});