Ajax

Q1:Access to XMLHttpRequest at ‘http://localhost:8080/chat’ from origin ‘http://127.0.0.1:8080’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.jquery.js:8475 GET http://localhost:8080/chat net::ERR_FAILED;

解决方法:
在ajax代码中加入:header(‘Access-Control-Allow-Origin: *’);

Q2 Access to XMLHttpRequest at ‘http://localhost:8080/chat’ from origin ‘http://127.0.0.1:8080’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.jquery.js:8475 GET http://localhost:8080/chat net::ERR_FAILED

解决方法:如果你试过了所有的以知道的方法,可是试一下将localhost换成127.0.0.1

你可能感兴趣的:(js)