0

I want to get a text from another domain using javascript or PHP. However, it gives me an error while trying to access another domain. I tried this piece of code:

$.ajax({
    url:'http://www.corsproxy.com/' +
        'en.wikipedia.org/wiki/Briarcliff_Manor,_New_York',
        type:'GET',
        success: function(data){
           $('#content').html($(data).find('#firstHeading').html());
        }
});

and the error is

has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Is there anyway that I can grab the content of the html for another domain?

Thanks!

Ataman
  • 2,530
  • 3
  • 22
  • 34

1 Answers1

1

As per browser's Single origin policy, it will not allow to read the other domains response, there server needs to add header for Access-Control-Allow-Origin to allow it read by browser for your domain.

Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to let a user agent gain permission to access selected resources from a server on a different origin (domain) than the site currently in use. A user agent makes a cross-origin HTTP request when it requests a resource from a different domain, protocol, or port than the one from which the current document originated.

ref https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

programtreasures
  • 4,250
  • 1
  • 10
  • 29