Share this question

Welcome to Teachnovice Q&A, where you can ask questions and receive answers from other members of the community.

This is a collaboratively edited question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Cross domain request with xmlHttpRequest and Paypal?

0 like 0 dislike
453 views

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!

asked Jan 24, 2015 by Alex  

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...