天天看點

解決JS跨域請求問題

//下面檔案是解決JS跨域請求問題
	header('Access-Control-Allow-Methods:OPTIONS, GET, POST');
	header('Access-Control-Allow-Headers:x-requested-with');
	header('Access-Control-Max-Age:86400');
	$_SERVER['HTTP_ORIGIN'] = isset($_SERVER['HTTP_ORIGIN'])?$_SERVER['HTTP_ORIGIN']:0 ;
	header('Access-Control-Allow-Origin:'.$_SERVER['HTTP_ORIGIN']);
	header('Access-Control-Allow-Credentials:true');
	header('Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS');
	header('Access-Control-Allow-Headers:x-requested-with,content-type');
	header('Access-Control-Allow-Headers:Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With');
    //上面檔案是解決JS跨域問題