2

In a browser extension, this my ajax call

var xhr = new XMLHttpRequest();
xhr.open('GET', window.location.href, true);
xhr.responseType = "arraybuffer";
xhr.onload = function(event) {
  alert(this.response);
};

I really do not understand why this giving me the error

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://people.cs.aau.dk/~torp/Teaching/E01/Oop/handouts/collections.pdf. (Reason: CORS header 'Access-Control-Allow-Origin' missing)

CORS comes into picture only once we are making the calls to other domain. But here I am making the call to the same domain. You can witness that in url xhr.open('GET', window.location.href, true);

What I am missing here ?

enter image description here

Rajeshwar
  • 2,290
  • 4
  • 31
  • 41
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307

1 Answers1

1

You can use a web service such as CrossOrigin.me to get ahead of it. I used a code like this and it did work for me:

$.ajax({
  url: 'https://crossorigin.me/http://people.cs.aau.dk/~torp/Teaching/E01/Oop/handouts/collections.pdf',
  jsonpCallback: 'callback',
  type: 'GET',
  success: function (data) {
    console.log(data);
  }
});

Fiddle: http://jsfiddle.net/L84u10yj/

I was able to make it working here:

Preview

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252