Javascript AngularJS 1.2跨源请求仅支持HTTP
有没有办法配置Angular应用程序使其可用? 我在使用一家工厂 顺便说一下,我使用localhost作为web服务器,但我向其他服务器(相同的网络)发出请求Javascript AngularJS 1.2跨源请求仅支持HTTP,javascript,html,angularjs,Javascript,Html,Angularjs,有没有办法配置Angular应用程序使其可用? 我在使用一家工厂 顺便说一下,我使用localhost作为web服务器,但我向其他服务器(相同的网络)发出请求 您可能希望按照此处的指定配置$httpProvider: 另一种方法是在前端服务器上创建一个简单的http代理,使外部请求看起来像来自同一服务器。您可能希望按照此处的指定配置$httpProvider: 另一种方法是在前端服务器上创建一个简单的http代理,使外部请求看起来像来自同一服务器。最终找到了解决方案。将在此处发布,也许它可以帮助
您可能希望按照此处的指定配置$httpProvider:
另一种方法是在前端服务器上创建一个简单的http代理,使外部请求看起来像来自同一服务器。您可能希望按照此处的指定配置$httpProvider:
另一种方法是在前端服务器上创建一个简单的http代理,使外部请求看起来像来自同一服务器。最终找到了解决方案。将在此处发布,也许它可以帮助其他人:
angular.module('demoApp.factories', [])
.factory('dataFactory', ['$http', function($http) {
var urlBase = 'external-server:8080';
var dataFactory = {};
dataFactory.getTest = function () {
//Note the $http method changed and a new parameter is added (callback)
//the value of the callback parameter can be anything
return $http.jsonp(urlBase + '/test?callback=myCallback');
};
return dataFactory;
}]);
控制器文件基本上只是调用此工厂:
angular.module('demoApp.controllers', []).controller('controller1', ['$scope', 'dataFactory',
function ($scope, dataFactory) {
$scope.status;
$scope.data;
dataFactory.getTest().success(function (data)
{
$scope.data = data;
}).error(function (error)
{
$scope.status = 'Unable to load customer data: ' + error.message;
});
终于找到了解决办法。将在此处发布,也许它可以帮助其他人:
angular.module('demoApp.factories', [])
.factory('dataFactory', ['$http', function($http) {
var urlBase = 'external-server:8080';
var dataFactory = {};
dataFactory.getTest = function () {
//Note the $http method changed and a new parameter is added (callback)
//the value of the callback parameter can be anything
return $http.jsonp(urlBase + '/test?callback=myCallback');
};
return dataFactory;
}]);
控制器文件基本上只是调用此工厂:
angular.module('demoApp.controllers', []).controller('controller1', ['$scope', 'dataFactory',
function ($scope, dataFactory) {
$scope.status;
$scope.data;
dataFactory.getTest().success(function (data)
{
$scope.data = data;
}).error(function (error)
{
$scope.status = 'Unable to load customer data: ' + error.message;
});
也许如果我使用jQuery来代替这个部分?也许如果我使用jQuery来代替这个部分,可能会重复?可能的重复只会使您能够跨域获取请求。例如,如果您想发布、放置或删除,您需要在客户端和API中启用CORS。这只允许您跨域执行GET请求。例如,如果您想发布、放置或删除,您需要在客户端和API中启用CORS。