4

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!

4
  • possible duplicate of Jquery $.ajax fails in IE on cross domain calls Commented Nov 20, 2013 at 15:21
  • Use $.ajax and use XDR for older IEs assuming paypal's sandbox does CORS Commented Nov 20, 2013 at 15:22
  • $.ajax is not working in IE10 an 11 and that's why I have tried with XHR Commented Nov 20, 2013 at 15:32
  • Where is your XDR? I do not see new XDomainRequest(); anywhere Commented Nov 20, 2013 at 15:41

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.