首先上图
在本地用ajax跨域访问请求时报错:
XMLHttpRequest cannot load/.........../ No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
解决方案如下:
1、如果请求的url是aspx页面,则需要在aspx页面中添加代码:Response.AddHeader("Access-Control-Allow-Origin", "*");
2、如果请求的url是PHP页面,则需要在PHP页面中添加代码:header("Access-Control-Allow-Origin: *");
3、如果请求的url是静态的html页面,则需要在页面中添加meta标签代码:<meta http-equiv="Access-Control-Allow-Origin" content="*" />
(参照:http://zjblogs.com/js/Access-Control-Allow-Origin.html)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
新手上路,切勿见怪。请各位大牛指教。