我尝试使用 Angularjs http service 来调用我的PHP API . 在浏览器中一切正常 . 但是,当我在我的Android手机上测试它时,它将无法正常工作 .
My Issue:
在Android PhoneGap应用程序中,每当我触发 Angularjs http service 时,即使Mobile与Internet连接,它也会始终触发 function (error)
.
我试试看,但他们的解决方案不起作用:
我还确保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="*" />
但它仍然没有工作 .
My Question:
-
Angularjs http服务无法在PhoneGap Mobile Application上运行,但只能在Web浏览器上运行吗?
-
除了
config.xml
之外,是否还有其他配置允许PhoneGap Mobile Application访问互联网?
Angularjs code:
$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.");
});
1 回答
看起来实际上我只是没有安装
whitelist
插件,对于我的情况,whitelist
插件没有默认安装 .由于我使用的是PhoneGap,而不是使用
cordova-plugin-whitelist@latest
,cordova create
,cordova plugin add cordova-plugin-whitelist
等命令 .我应该使用:
phonegap plugin add cordova-plugin-whitelist
安装Whitelist插件后,一切正常 .
所以,
Angularjs http服务能够在PhoneGap Mobile Application上运行 .
除了config.xml之外,我们必须确保安装了所有必需和必需的插件,例如Whitelist插件 .