本文通过设置Access-Control-Allow-Origin来实现跨域。
例如:客户端的域名是client.w3cschool.cc,而请求的域名是server.w3cschool.cc。
如果直接使用ajax访问,会有以下错误:
1 | XMLHttpRequest cannot load http://server.w3cschool.cc/server.php. No 'Access-Control-Allow-Origin' header is present on the requested resource.Origin 'http://client.w3cschool.cc' is therefore not allowed access. |