dimanche 25 mai 2014

JavaScript - Croix domaine demande avec xmlHttpRequest et Paypal - Stack Overflow


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!



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!


0 commentaires:

Enregistrer un commentaire