Dan*_*mil 5 ajax angularjs cordova
我正在使用AngularJS $ http从远程服务器获取一些数据.它在浏览器中工作,但在phonegap开发者应用程序中没有.但是,ajax正在发挥作用.可能是什么问题呢!!
这是我正在使用的代码.
$http({
url: domain + "modulesinfo/list",
method: "GET",
//Added after some research // I'm testing on local server
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
})
.success(function(data){
$scope.modules = data.response;
$scope.$apply();
})
.error(function(){
navigator.notification.alert("You are damned", function(){
}, "Not working", "OK");
});
Run Code Online (Sandbox Code Playgroud)
经过一些研究,我尝试添加标题,但这没有用.
$http.jsonp(domain + "modulesinfo/list?callback=JSON_CALLBACK")
.success(function(data){
console.log(data);
$scope.modules = data.response;
})
.error(function(){
console.log(data);
});
Run Code Online (Sandbox Code Playgroud)
这解决了我的问题。希望它对其他人有帮助。在我的例子中,使用 url 添加回调=JSON_CALLBACK 是有效的。