0

I'm getting "401 unauthorized" for the below ajax call,

jQuery.ajax({
                url: url1,
                headers: { "Authorization": "Basic Auth"},
                dataType: "json",
                type: "GET",
                timeout: 190000,
                success: response3 });

So I tried creating the same using XMLHttpRequest as below,

 var xhr = new XMLHttpRequest(),
method = "GET";
xhr.open(method, url1, true);
xhr.setRequestHeader("Authorization","Basic Auth");
xhr.onreadystatechange = function () {
if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
  console.log(xhr.responseText);
  response3(xhr.responseText);
  }
};
xhr.send();

and it is working fine. What's the issue in JQuery.ajax? and why it is working fine using XMLHttpRequest?

irs102info
  • 526
  • 1
  • 6
  • 16

0 Answers0