如何解决跨源请求被阻止..? [英] How to resolve cross-origin request blocked..?
问题描述
< !DOCTYPE html >
< html >
< head >
< title > < / title >
< script src = https://ajax.googleapis.com/ajax/libs/an gularjs / 1.4.3 / angular.min.js > < / script >
< script 类型 = text / javascript >
var app = angular.module(' myApp',[]);
app.controller(' myCtrl',函数($ scope,$ http){
// $ http.get('http :// localhost:24844 / SettingsRestService.svc / GetListitems / 12')
$ http.get(' http://demo3.engquote.co.in/SettingsRestService.svc/GetListitems/12')
.then( function (回复){
$ scope.Customer = response.data.RESTGetListitemsResult;
});
});
< / script >
< / head >
< body >
< div ng-app = myApp ng-controller = myCtrl >
< table class = table table-bordered >
< thead >
< tr >
< th >
客户ID
< / th >
< th >
公司名称
< / th >
< th >
城市
< / th >
< / tr >
< / thead >
< tr ng-repeat = 客户中的x >
< td >
{{x.ListItemID}}
< / td >
< td >
{{x.ListItemDescription}}
< ; / td >
< td >
{{x.ListGroupID}}
< / td >
< / tr >
< / table >
< / div >
< / body >
< / html >
我尝试过:
我正在使用AngularJS尝试上面的get方法...它们完全适用于localhost ...并且我在服务器中托管服务...
url:http: //demo3.engquote.co.in/SettingsRestService.svc/GetListitems/12
他们抛出的错误是:Cross-Origi n请求已阻止:同源策略不允许在http://demo3.engquote.co.in/SettingsRestService.svc/GetListitems/12上读取远程资源。 (原因:CORS标题'Access-Control-Allow-Origin'与'http://demo3.engquote.co.in,*'不匹配。
如何重新发送此错误... plz help
范围,
http){
//
http.get('http:// localhost:24844 / SettingsRestService。 SVC / GetListitems / 12' )跨度>
<!DOCTYPE html>
<html>
<head>
<title> </title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope, $http) {
//$http.get('http://localhost:24844/SettingsRestService.svc/GetListitems/12')
$http.get('http://demo3.engquote.co.in/SettingsRestService.svc/GetListitems/12')
.then(function (response) {
$scope.Customer = response.data.RESTGetListitemsResult;
});
});
</script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<table class="table table-bordered">
<thead>
<tr>
<th>
Customer ID
</th>
<th>
Company Name
</th>
<th>
City
</th>
</tr>
</thead>
<tr ng-repeat="x in Customer">
<td>
{{x.ListItemID}}
</td>
<td>
{{x.ListItemDescription}}
</td>
<td>
{{x.ListGroupID}}
</td>
</tr>
</table>
</div>
</body>
</html>
What I have tried:
I m trying the above get method using AngularJS...they perfectly work on localhost... and i m host the service in server...the
url: http://demo3.engquote.co.in/SettingsRestService.svc/GetListitems/12
They throw error is: "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://demo3.engquote.co.in/SettingsRestService.svc/GetListitems/12. (Reason: CORS header 'Access-Control-Allow-Origin' does not match 'http://demo3.engquote.co.in, *')."
How to reslove this error...plz help
scope,
http) { //
http.get('http://localhost:24844/SettingsRestService.svc/GetListitems/12')
这篇关于如何解决跨源请求被阻止..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!