前端Jquery-Ajax跨域请求,并携带cookie 前端Jquery-Ajax跨域请求,并携带cookie

前端Jquery-Ajax跨域请求,并携带cookie

1. 需现在服务端允许跨域,允许携带cookie

因服务端脚本语言不同,自行搜索设置

2. 前端Ajax跨域请求代码

$.ajax({
                type: "POST",
                url: "http://127.0.0.1:8000/api/login",
                data: JSON.stringify({'num': 1}), dataType: 'json', xhrFields: { withCredentials: true //允许跨域带Cookie }, success: function(data) { console.log(data) } })

目录

1. 需现在服务端允许跨域,允许携带cookie

因服务端脚本语言不同,自行搜索设置

2. 前端Ajax跨域请求代码

$.ajax({
                type: "POST",
                url: "http://127.0.0.1:8000/api/login",
                data: JSON.stringify({'num': 1}), dataType: 'json', xhrFields: { withCredentials: true //允许跨域带Cookie }, success: function(data) { console.log(data) } })

猜你喜欢

转载自www.cnblogs.com/huangcong/p/12307585.html