Origin XMLHttpRequest not allowed Access-Control-Allow-Origin

I am trying to get plain text via HTTP from JavaScript:

$(function() { $.get("http://mydomain.com/path", function(result) { console.log(result); }); }); 

The result should be text/html , but basically it is just a simple key string, without HTML tags. The page is under my control, but comes third-party (closed source), so I can not change the Java that serves this page.

How can I get the contents of this page with JavaScript?

0
source share
2 answers

You simply use either PHP / ASP your server language to receive a cross-domain access request or use a service such as the ajax cross-domain service created by Yahoo !.

It uses JSONP, which is allowed to make very strict cross-domain requests, but asking Yahoo! they will retrieve any page on the web.

http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/

+4
source

You cannot request this page because of the Same origin policy , unless this page has explicitly authorized CORS for you.

Either a server-side proxy with a service like YQL, get it as JSONP, or get another service to enable CORS for your domain.

+2
source

Source: https://habr.com/ru/post/907207/


All Articles