Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

javascript - 请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许原点'...'访问(No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '…' is therefore not allowed access)

I'm using .htaccess to rewrite urls and I used html base tag in order to make it work.(我正在使用.htaccess重写网址,我使用了html基本标记以使其正常工作。)

Now, when I try to make an ajax request I get the following error:(现在,当我尝试发出ajax请求时,我收到以下错误:) XMLHttpRequest cannot load http://www.example.com/login.php .(XMLHttpRequest无法加载http://www.example.com/login.php 。) No 'Access-Control-Allow-Origin' header is present on the requested resource.(请求的资源上不存在“Access-Control-Allow-Origin”标头。) Origin ' http://example.com ' is therefore not allowed access.(因此,不允许来源“ http://example.com ”访问。)   ask by Th3lmuu90 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use addHeader Instead of using setHeader method,(使用addHeader而不是使用setHeader方法,)

response.addHeader("Access-Control-Allow-Origin", "*"); * in above line will allow access to all domains .(*在上面一行将允许access to all domains 。) For allowing access to specific domain only :(access to specific domain only允许access to specific domain only :) response.addHeader("Access-Control-Allow-Origin", "http://www.example.com"); Check this blog post .(查看此blog post 。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...