ajax Access-Control-Allow-Origin跨域问题

来源:互联网 发布:js获取list长度 编辑:程序博客网 时间:2024/05/21 09:46

今天访问本地ajax竟然报跨域的错:

XMLHttpRequest cannot loadhttp://localhost:8080/bss_server/isLoginBss?userName=AMCTJ013. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access

有两个解决方案:

(1)将datatype="json"改为dataType="jsonp"

$.ajax({url: 'http://localhost:8080/bss_server/isLoginBss?userName=AMCTJ013',type: 'GET'dataType:'jsonp',success: function(data) {}});
(2)在服务端加上header  Access-Control-Allow-Origin:*


0 0