2023年6月20日发(作者:)
跨域请求webapi设置headers的解决⽅案解决跨域调⽤服务并设置headers 主要的解决⽅法需要通过服务器端设置响应头、正确响应options请求,正确设置 JavaScript端需要设置的headers信息 ⽅能实现。1.第⼀步 服务端设置响应头,在webapi的做如下设置 1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
12
13
14
///
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$("#btnSumit").click(function() {varTicket = $.cookie("token");varmodel = {id: 1};$.ajax({type:
"POST",url:
"",data: ify(model),contentType:
"application/json; charset=utf-8",dataType:
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
dataType:
"json",beforeSend:
function(xhr) {// //发送ajax请求之前向http的head⾥⾯加⼊验证信息uestHeader("token", Ticket);
// 请求发起前在头部附加token},success:
function(data, status) {if(code ==
"401") {alert();}else{alert(ify(data))}},//error: function (XMLHttpRequest, textStatus, errorThrown) {// alert();// alert(tate);// alert(textStatus);//},complete:
function() {}});});
2023年6月20日发(作者:)
跨域请求webapi设置headers的解决⽅案解决跨域调⽤服务并设置headers 主要的解决⽅法需要通过服务器端设置响应头、正确响应options请求,正确设置 JavaScript端需要设置的headers信息 ⽅能实现。1.第⼀步 服务端设置响应头,在webapi的做如下设置 1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
12
13
14
///
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$("#btnSumit").click(function() {varTicket = $.cookie("token");varmodel = {id: 1};$.ajax({type:
"POST",url:
"",data: ify(model),contentType:
"application/json; charset=utf-8",dataType:
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
dataType:
"json",beforeSend:
function(xhr) {// //发送ajax请求之前向http的head⾥⾯加⼊验证信息uestHeader("token", Ticket);
// 请求发起前在头部附加token},success:
function(data, status) {if(code ==
"401") {alert();}else{alert(ify(data))}},//error: function (XMLHttpRequest, textStatus, errorThrown) {// alert();// alert(tate);// alert(textStatus);//},complete:
function() {}});});
发布评论