[英]Phonegap on Windows Phone 8.1 with AngularJS can't retrieve JSONP from my API
I made an app with Phonegap Cordova and when I test it on Android everything is OK, but when I test it on Windows Phone 8.1 it gives me the following error: 我用Phonegap Cordova制作了一个应用程序,当我在Android上测试它时一切正常,但是当我在Windows Phone 8.1上测试时,它给了我以下错误:
APPHOST9601: Can't load http://www.example.com/apiv2/process.php/Login2?Email=xxxx@xxxx.com&Password=7c4a8d09ca3762af61e59520943dc26494f8941b&callback=angular.callbacks._0 . APPHOST9601:无法加载http://www.example.com/apiv2/process.php/Login2?Email=xxxx@xxxx.com&Password=7c4a8d09ca3762af61e59520943dc26494f8941b&callback=angular.callbacks._0 。 An app can't load remote web content in the local context. 应用无法在本地上下文中加载远程Web内容。 File: index.html. 文件:index.html。 I am using Angularjs and Onsenui. 我正在使用Angularjs和Onsenui。
EDITED: 编辑:
The code is: 代码是:
var apiprincipal = 'http://www.example.com/apiv2/process.php/';
// Log In Controller
app.controller('loginController', [ '$http', '$scope', '$rootScope', function($http, $scope, $rootScope){
$scope.email = '';
$scope.password = '';
$scope.loginN = function(){
if($scope.email==='' && $scope.password===''){
ons.notification.alert({message: "Vo\u00E7\u00EA dever\u00E1 preencer os dois campos usu\u00E1rio e senha"});
} else {
modal.show();
$http.jsonp(apiprincipal+'Login2?Email='+$scope.email+'&Password='+CryptoJS.SHA1($scope.password)+'&callback=JSON_CALLBACK').success(
function(response){
if(response.status=='ok'){
console.log('WORKING')
} else{
modal.hide();
}
}
);
}
};
}]);
First, try removing some unnecessary code for a more readable question. 首先,尝试删除一些不必要的代码以获得更易读的问题。
Your URL should look like this 您的网址应如下所示
$http.jsonp(apiprincipal+'Login2?Email='+$scope.email+'&Password='+CryptoJS.SHA1($scope.password)+'&_jsonp=JSON_CALLBACK')
in case that &_jsonp=JSON_CALLBACK
doesn't work, change it for ?_jsonp=JSON_CALLBACK
如果&_jsonp=JSON_CALLBACK
不起作用,请将其更改为?_jsonp=JSON_CALLBACK
I was with the same in my app and yesterday I was reading an article, so I fix it like this: 我在我的应用程序中使用了相同的内容,昨天我正在阅读一篇文章,所以我修复它:
http://amyurl.com/wp-json/posts?_jsonp=JSON_CALLBACK
now it is working. 现在它正在运作。
I had the same issue when targeting Windows 8.1. 我针对Windows 8.1时遇到了同样的问题。
First I checked my backend supported CORS. 首先,我检查了我的后端支持CORS。 I didn't find a way to keep JSONP in Windows 8.1, I had to change it into a simple GET method. 我没有找到在Windows 8.1中保留JSONP的方法,我不得不将其更改为简单的GET方法。 Then I removed 'callback' from the URL. 然后我从URL中删除了“回调”。
Referring to your code, it should look like that 参考你的代码,它应该是这样的
$http.get(apiprincipal+'Login2?Email='+$scope.email+'&Password='+CryptoJS.SHA1($scope.password)).success(function(response) {
if(response.status=='ok'){
console.log('WORKING');
} else{
modal.hide();
}
});
It worked fine for me, hope it can help someone else. 它对我来说很好,希望它可以帮助别人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.