1

I have been following some articles to resolve this issue but none worked. I have a javascript function using XMLHttpRequest to call a paypal api. This function works with Firefox/Chrome but fails in IE 11 (I have not tried with previous IE versions though). With IE 11, at line xhr.send(); I get "Network Error" and then it dies. In the console, as soon as the page loads even before the web call..I can see,

SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.

and below is a javascript function which I am calling to get the access token from paypal.

 function getAccessToken(strClientID,strSecretKey){
        try
            {
                //***********************code for access token call starts***************************
                var strbody = 'grant_type=client_credentials';
                var xmlhttp = new XMLHttpRequest();
                xmlhttp.open('POST', 'https://api.sandbox.paypal.com/v1/oauth2/token', false);
                xmlhttp.setRequestHeader("Content-Type", "application/x-
                www-form-urlencoded");
                xmlhttp.setRequestHeader('Authorization', 'Basic ' + window.btoa(strClientID+':'+strSecretKey)); //in prod, you should encrypt user name and password and provide encrypted keys here instead
                xmlhttp.send(strbody);
                var response = xmlhttp.responseText;
                var obj = JSON.parse(response);
                var access_token = obj.access_token; 
                return access_token;
                //***********************code for access token call ends***************************
            }
            catch(err){

                alert(err.message);
            }
    } 

I have been following posts such as this which suggest to use CORS. So, I have tried the function createCORSRequest(method, url) as mentioned here but still getting the same error.

Later, I thought of using JQuery instead of Javascript and I converted the above function to below ajax call

                    $.ajax({

                            method:"POST",
                            url : "https://api.sandbox.paypal.com/v1/oauth2/token",
                            data:{"grant_type":"client_credentials"},
                            datatype:'json', 
                            async: false,  
                            contentType: 'application/x-www-form-urlencoded; charset=UTF-8',                                
                            headers: {
                                "Authorization": "Basic " + btoa(client_id+":"+strKey)
                            },
                            success: function(response) {

                                alert('Ajax call successfull !!');

                            },
                            error: function(XMLHttpRequest,status,error) {
                                alert('Ajax call NOT successfull !!'+error);
                            }

                        });

but still this ajax call is printing "Ajax call successfull !!" for firefox/chrome and with IE 11, I get "Ajax call NOT successfull !! NetworkError".

here I read about using ActiveXObject if the browser is IE...still no luck..

I am not sure if I am in the right direction or just getting confused.. just to remind that it works fine with Firefox and Chrome but not with IE 11.

Help please.

thanks

Sanket
  • 43
  • 7

0 Answers0