20

I make a GET request using Postman extension and obtain a response, but if I make the same request using jQuery I receive a typical error:

XMLHttpRequest cannot load http://www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l=020039535&t=&p=0&e=50L-I. No 'Access-Control-Allow-Origin' header is present on the requested resource.

Why does this happen?

My javascript code is simple:

function getTiempo (dni, piscina, prueba) {
    $.ajax({
        async: false,
        type: "GET",
        url: "http://www.rfen.es/publicacion/ranking/resultsBySwimmer.asp?l="+dni+"&t=&p="+piscina+"&e="+prueba
    })
    .done(function (data) {
        console.log(data);
        return data;
    });
}

The Postman extension is not on the same domain either, why does it get a response?

Will Nielsen
  • 542
  • 1
  • 5
  • 16
Raugaral
  • 1,303
  • 13
  • 25
  • I found the answer here: http://stackoverflow.com/a/20035319/3370595 – Raugaral Aug 14 '14 at 05:02
  • Your answer can be found below. Its a problem with data types i think. http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource/20035319#20035319 – Maleen Abewardana Aug 14 '14 at 05:04

1 Answers1

11

Just to help future fellows seeking for this specific question: Why POSTMAN works and my jQuery don't!

The answer is quite simple, actually: Chrome Extensions are allowed to do so!

Regular web pages can use the XMLHttpRequest object to send and receive data from remote servers, but they're limited by the same origin policy. Extensions aren't so limited. An extension can talk to remote servers outside of its origin, as long as it first requests cross-origin permissions.

https://developer.chrome.com/extensions/xhr

Beccari
  • 761
  • 12
  • 20
  • 4
    funny fact #1: If you open the debug console on same POSTMAN tab, you will be able to execute your $.ajax, the request will work, because you are in the chrome extension "context"!! – Beccari Dec 31 '14 at 14:38