ajax跨域请求:No 'Access-Control-Allow-Origin' header is present on the requested resource
2016-12-13 12:46
951 查看
ajax跨域请求报错解决办法
<script type="text/javascript">$(document).ready(function () {$.ajax({type : "POST",url : "http://127.0.0.1:9999/app/getToken.ya",success : function(data) {var token = eval(data).rows[0];window.location.href="http://10.6.2.26:8080/BOE/OpenDocument/opendoc/openDocument.jsp?token="+token;}});})</script>报错:[Web浏览器] "XMLHttpRequest cannot load http://127.0.0.1:9999/app/getToken.ya. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:8020' is therefore not allowed access."/HelloHBuilder/index.html (0)原因是ajax跨域请求被服务器端拒绝。只需要在服务器端加入:response.setHeader("Access-Control-Allow-Origin", "*");
即可完美解决,至于安全性问题,后期再说。
相关文章推荐
- 解决 ajax跨域 No 'Access-Control-Allow-Origin' header is present on the requested resource.
- AJAX跨越、JS跨越请求 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin
- 本地Ajax跨域访问 No 'Access-Control-Allow-Origin' header is present on the requested resource.
- 跨域问题:No 'Access-Control-Allow-Origin' header is present on the requested resource.
- jquery ajax No 'Access-Control-Allow-Origin' header is present on the requested resource
- 跨域问题:“No 'Access-Control-Allow-Origin' header is present on the requested resource”
- js跨域访问,no 'access-control-allow-origin' header is present on the requested resource
- JS跨域:No 'Access-Control-Allow-Origin' header is present on the requested resource
- 跨域 No 'Access-Control-Allow-Origin' header is present on the requested resource
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is there
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- No 'Access-Control-Allow-Origin' header is present on the requested resource解决方法
- 解决 js ajax跨域访问报“No 'Access-Control-Allow-Origin' header is present on the requested resource.”错误
- “No 'Access-Control-Allow-Origin' header is present on the requested resource”
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- No 'Access-Control-Allow-Origin' header is present on the requested resource
- No 'Access-Control-Allow-Origin' header is present on the requested resource