在PHP文件上加上 header("Access-Control-Allow-Origin: *"); //全域名 header("Access-Control-Allow-Credentials: true"); //是否可以携带cookie header("Access-Control-Allow-Methods: POST,GET,PUT,OPTIONS,DELETE"); //允许请求方式 header("Access-Control-Allow-Headers: X-Custom-Header"); //允许请求字段,由客户端决定 header("Content-Type: text/html; charset=utf-8"); //返回数据类型( text/html; charset=utf-8、 application/json; charset=utf-8 )