Cross domain request with xmlHttpRequest and Paypal

跟風遠走 提交于 2019-12-12 11:55:52

问题


I am trying to do a cross domain request with XMLHttpRequest object, because with $.ajax it doesn't work in IE, only in Chrome, Firefox and Safari. Below is a code sample

$("#btn").click(function () {
    CallWithXhr();
});

function CallWithXhr() {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "https://www.sandbox.paypal.com/cgi-bin/webscr", true);
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
    xhr.send(); 
    xhr.onload = function () {
        var responseText = xhr.responseText;
        console.log(responseText);     
    };    
    xhr.onerror = function () {
        console.log('There was an error!');
    };
}

I need this call because I want to add a product to the Paypal Shopping Cart without redirecting to the Paypal Shopping Cart. I have made this thing with $.ajax but it didn't work in Internet Explorer 10 and 11.

The errors I get in IE are:

SEC7126: Redirects are not allowed for CORS preflight requests.
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.

In Chrome I get only one error for this script:

XMLHttpRequest cannot load https://www.sandbox.paypal.com/cgi-bin/webscr. The request was redirected to 'https://www.sandbox.paypal.com/home', which is disallowed for cross-origin requests that require preflight.

Any ideas about this issue? Thanks!

来源:https://stackoverflow.com/questions/20099792/cross-domain-request-with-xmlhttprequest-and-paypal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!