用angularjs或者ajax进行请求时,如果请求的url非本地服务,会报类似
XMLHttpRequest cannot load http://192.168.1.64/jsson. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
的错误。
针对这个问题,最好的解决方案为在server端进行配置,允许js的跨域请求。
- server端为java
response.setHeader(“Access-Control-Allow-Origin”, “*”); - server端为php
header(“Access-Control-Allow-Origin:*”);