our project used to deal with token expiration. The back end returns an expired error code and the front end jumps to the login page.
A page is a form page. After successful submission, jump to B page
function request(url,data,header) {
$.ajax({
url: url,
type: "post",
data: data,
header: header,//headertoken
success: function(data) {
//code1
if(data.code == 1) {
window.location.href = "B.html"
}
//code2 token
if(data.code == 2) {
window.location.href = "login.html"
}
}
})
}
request("submitUrl",data,header)//
customers feel that this interactive experience is too poor, so they want to change it to
when the token expires, the backend returns an expired error code, frontend to judge and then sends a request to update the token before sending the request, so that the user can complete the process without doing anything.
function request(url,data,header) {
$.ajax({
url: url,
type: "post",
data: data,
header: header,//headertoken
success: function(data) {
//code1
if(data.code == 1) {
window.location.href = "B.html"
}
//code2 token
if(data.code == 2) {
window.header.token =
requestToken(header)//token
}
}
})
}
request("submitUrl",data)//
//token
function requestToken() {
$.ajax({
url: "getToken",
data: data,
type:"post",
success: function(data) {
//code1
if(data.code == 1) {
return data.token
}
}
})
but I was stuck by a process problem. How can I send the previous request again (without letting the user operate) after getting this updated token,? is it feasible for me to think so?