今天访问本地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:*