XMLHttpRequest cannot load http://192.168.1.140:8080/users?. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. index.html:1
XMLHttpRequest cannot load http://192.168.1.140:8080/profile. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. index.html:1
由于浏览器的安全限制,网络连接的跨域访问时不被允许的,当然其中也包括了XmlHttpRequest。但是,有些时候我们需要通过跨域访问来获取一些资源,例如:
•作为用户,我们需要在自己的网站用AJAX调用一些其他网站提供的服务,这些服务常常是一些HTTP GET形式的API。而AJAX的基础是XmlHttpRequest,跨域的XmlHttpRequest是不被允许的„„
•作为服务提供者,我们想让用户只是简单的在他们的网页中远程引用我们的脚本文件,并加入一些少量的html代码就能使用我们的服务,而不用在服务器端做任何的改变。当然,XmlHttpRequest也是行不通的。