简体   繁体   中英

Bypassing cross origin policy using JQuery/javascript with no access to remote server

I want to retrieve the following JSON using javascript:

https://www.gov.uk/api/organisations/skills-funding-agency

If I do a JsonP call I get:

callback=jQuery1113043552865949459374_1434727982051&_=1434727982052' because its MIME type ('application/json') is not executable, and strict MIME type checking is enabled.

If I do a JSON call I get:

XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Is this at all possible? I've been googling for hours without any success. I've seen some PHP solutions but ideally don't want to have to install PHP to do this.

Thanks in advance!

If you don't wanna install PHP to do this, why did you tag with ? You need to use a Server Side Script like Proxy PHP file, that reads the content and executes it correctly.

Proxy.php :

<?php
    header("Content-type: application/json");
    die(file_get_contents($_GET["url"]));
?>

And call it like this:

url: "proxy.php?url=http://gov.uk/blah/blah"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM