这里的概念我正在做的是,将发布请求发送到其他域以使用$ resource来检索详细信息......
我对使用$ resource ...感到震惊,请看下面的错误..
XMLHttpRequest无法加载http://exampledomian.com/api/getCountries/123web/0/0/0。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许来源'http:/ localhost'访问。
factory.js
var factories = angular.module('AngularApp.factories',[]);
factories.factory("ApiListFactory", ['$resource', function($resource) {
return $resource('http://exampledomian.com/api/getCountries/:ain/:rtmp/:aacp/:mms',
{ain:'123web', rtmp :0,aacp:0,mms:0},{req:{method:'POST'
}});
}]);
enter code here
Controller.js
var AngularApp = angular.module('AngularApp',
['ngRoute','ngResource','AngularApp.factories']);
AngularApp.config(function($interpolateProvider){
$interpolateProvider.startSymbol('{$');
$interpolateProvider.endSymbol('$}');
});
AngularApp.config(function($httpProvider) {
//Enable cross domain calls
$httpProvider.defaults.useXDomain = true;
//Remove the header used to identify ajax call that would prevent CORS from working
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
});
AngularApp.config(['$routeProvider',function($routeProvider){
$routeProvider.
when('/',{
templateUrl: '/static/ag_template/apiList.html',
controller:'MainController'
});
}]);
AngularApp.controller('MainController',['$scope','ApiListFactory', function($scope,ApiListFactory){
var hi=ApiListFactory.query();
console.log(hi);
}]);
我有两个问题:
你的帮助真的很明显......