header("Access-Control-Allow-Origin:*"); header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, X-Token"); header("Access-Control-Allow-Methods:PUT,POST,GET,DELETE,OPTIONS"); if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){ return true; exit(); // 比如是跨域请求,客户端搜索a,第一次搜索时,会发生一次options请求。如果请求链接不变,则不会再次发起options请求 }