简体   繁体   中英

XMLHttpRequest cannot load for No 'Access-Control-Allow-Origin' header

I am trying to load a div using:

<script>
    $("#details").load('http://localhost:31075/ #user');
</script>

But getting acess restriction.

XMLHttpRequest cannot load http:// localhost :31075/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http:// localhost :43302' is therefore not allowed access.

So how can I define access headers on the earlier page as that is also my MVC app.

您可以尝试使用此链接http://hayageek.com/cross-domain-ajax-jquery-without-cors ,该链接可以解决您的错误,并且任何服务器端语言都可以使用。

If you only want to fetch data from server, JSONP could be a solution since it is very easy to implement.

If you want to be able to made not only GET, but also POST, PUT etc., you can use cross origin resource sharing, CORS on server. Since you didn't mention which server side language you have, have a look at here . It contains some code snippets for various languages. Basically server needs to send Access-Control-Allow-Origin header

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