header頭設置解決 「已攔截跨源請求:同源策略禁止讀取位於 http://back/test/test 的遠程資源。(緣由:CORS 頭缺乏 'Access-Control-Allow-Origi

跨域請求錯誤提示以下圖:php

解決方法在請求的php頁面添加header頭:json

代碼以下:跨域

public function test()
	{
		//支持全域名訪問,不安全,部署後須要固定限制爲客戶端網址
		header('Access-Control-Allow-Origin:*'); 
		//支持的http 動做
		header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); 
		//響應頭 請按照本身需求添加。
		header('Access-Control-Allow-Headers:x-requested-with,content-type'); 
		$arr = Querys::selects("index_goods");
		echo json_encode($arr);
	}
相關文章
相關標籤/搜索