| 1.jsonp 
 script标签会把请求回来的所有内容当做js代码来执行script有默认type属性 值是text/javascript 不管src请求什么文件把里面的代码当做字符串读取
 利用这个特性 就可以在php文件准备相对于的函数名字符串 js代码也需要准备好函数
 请求回来就直接调用定义好的函数
 echo "fn()"
 function fn(res){
             console.log('jsonp请求回来了')
             console.log(res);
         }
 2.服务器代理 
 使用nginx服务器代理注意 nginx不能使用中文(包括文件名) 而且只能发送GET请求
 
 location = /gx(代理标识符可任意) {
              proxy_pass http://127.0.0.1/server/proxy.php(请求文件路径);
          }
 
 
    xhr.open('GET', '/gx')
 3.cors 
 在请求的php文件添加 <?php
header("Access-Control-Allow-Origin:*");
header("Access-Control-Request-Methods:GET, POST, PUT, DELETE, OPTIONS");
header('Access-Control-Allow-Headers:x-requested-with,content-type,test-token,test-sessid');
?>
 
 |