简体   繁体   中英

Why isn't cross origin policy enforced?

I have this code:

       $.getJSON("https://restcountries.eu/rest/v2/name/" + $("#nameOfCountry").val(),
        { fullText: "true" }, function (data) {
            console.log(data[0]);
            $('#answer').html(data[0].capital);
       });

I get the response from the other server. So my question is: why doesn't the browser enforce the cross origin policy here?

The Same Origin Policy is never enforced by the server. It is enforced by the browser.

In this case, the server has used the CORS standard to include an Access-Control-Allow-Origin header that tells the browser that it has permission to share the data with any other site.

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