【发布时间】:2018-09-25 21:07:08
【问题描述】:
我尝试使用 Angularjs http 服务 来调用我的 PHP API。在浏览器中一切正常。但是,当我在我的 Android 手机上测试它时,它不起作用。
我的问题:
在 Android PhoneGap 应用程序中,每当我触发 Angularjs http 服务时,它总是会触发function (error),即使手机已连接到互联网。
我试过看看这个,但他们的解决方案不起作用:
- Angular $http.get() does not work in Phonegap DevApp
- Cordova 5.3.1 Android app can't access the internet
我还确保 Phonegap config.xml 允许 Internet 访问权限:
<access allows-arbitrary-loads-in-media="true" allows-arbitrary-loads-in-web-content="true" allows-local-networking="true" origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
但是还是不行。
我的问题:
- Angularjs http 服务不能在 PhoneGap 移动应用程序上工作,而只能在 Web 浏览器上工作吗?
- 除了
config.xml之外,还有没有其他配置可以让PhoneGap Mobile App访问互联网?
Angularjs 代码:
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
$http({
method: 'POST',
data: {
'email' : $scope.email,
'password' : $scope.password,
},
url: 'https://unsurfaced-cross.000webhostapp.com/PGLogin.php'
}).then(function (response){
$scope.users = response.data;
if(response.data[0]=="LOGIN"){
alert("Successful Login");
$window.location.href = './homepage.html';
}else{
alert("Login Failed. Incorrect Email or Password.");
}
},function (error){
alert("Please ensure You are connected to Internet.");
});
【问题讨论】:
-
错误回调中的错误说明了什么?
标签: android angularjs cordova phonegap angularjs-http