怎么用php跨域请求
生活随笔
收集整理的這篇文章主要介紹了
怎么用php跨域请求
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
header(“Access-Controller-Allow-Origin:*”);//用于解決同源策略,跨域訪問
jQuery里ajax請求攜帶cookie:
$.ajax({
url:"{:url(‘index/Hello/api’)}",
type:“get”,
xhrFields: {
withCredentials: true // 攜帶跨域cookie
},
success:function(data,suc){
console.log(data.data);
}
})
header(“Access-Control-Allow-Credentials:true”);//用于接收跨域cookie
$_COOKIE[“name”];全局變量獲取;
headers:{“token”:“liu”}axios里config配置請求頭
header(‘Access-Control-Allow-Headers:token’);//跨域響應設置請求頭
總結
以上是生活随笔為你收集整理的怎么用php跨域请求的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: openmv自然光下寻找激光点
- 下一篇: 员工管理能力怎么提高?不妨使用现代工时表