[英]Cross domain issue while posting in third party site in angular js
HTML Code:
<div ng-app="myApp" ng-controller="myController">
<div>
<input type="button" data-ng-click="submit()" value="Continue"></input>
</div>
</div>
After click on Continue button posting the thirdparty site without changing the URL.In IE browser it's working fine but other browsers are not working, I am facing the below issue.. 单击继续按钮发布第三方站点而不更改URL后。在IE浏览器中,它可以正常工作,但其他浏览器无法正常工作,我面临以下问题。
Angular Code:
var myAppex = angular.module("myApp", []);
myAppex.controller('myController', ['$scope','$window', '$http','$location',
function($scope, $window, $http,$location) {
$scope.submit = function() {
var headersSend = {
'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Allow-Headers': 'X-Custom-Header,x-requested-with, Content-Type, origin, authorization, accept, client-security-token,Overwrite, Destination, User-Agent, Translate, Range, Content-Range, Timeout, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control, Location, Lock-Token, If', 'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS, PUT', 'Content-Type': 'application/json;charset=utf-8', 'Accept': 'application/json', }; $http({method: 'POST', url:respData.thirdpartyurl, //ex: https://en.wikipedia.org/wiki/W3Schools crossDomain: true, processData: true, dataType: 'jsonp', headers : headersSend, data: respData.somedata }).success(function(data,status, headers, config) { $('body').html(data); headers = headersSend; }).error(function(data, status, headers, config) { if(status == 400) { $scope.messages = data; } else { alert('Unexpected server error.'); }
});
};
}]);
XMLHttpRequest cannot load https://en.wikipedia.org/wiki/W3Schools . XMLHttpRequest无法加载https://en.wikipedia.org/wiki/W3Schools 。 No 'Access-Control-Allow-Origin' header is present on the requested resource.
所请求的资源上没有“ Access-Control-Allow-Origin”标头。 Origin ' http://localhost:8081 ' is therefore not allowed access.
因此,不允许访问源' http:// localhost:8081 '。 The response had HTTP status code 501..
响应的HTTP状态码为501。
Any help much appreciated . 任何帮助,不胜感激。 Thanks in advance
提前致谢
use corsproxy npm install corsproxy
. 使用corsproxy
npm install corsproxy
。
then do a corsproxy
. 然后做一个
corsproxy
。 It'll start on 1337/9292.. Depending on where it starts, (lets say 9292) append your external url ie in your case " https://en.wikipedia.org/wiki/W3Schools " with http://localhost:9292/en.wikipedia.org/wiki/W3Schools and it'll work fine. 它将从1337/9292开始。根据它的开始位置,(假设是9292)附加您的外部URL,即在您的情况下,使用http:// localhost附加“ https://en.wikipedia.org/wiki/W3Schools ” :9292 / en.wikipedia.org / wiki / W3Schools ,它将正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.