php处理ajax post请求超时,php – 如何处理AJAX请求中的会话超时
考慮返回一個(gè)http狀態(tài)為401,一個(gè)
JSON對(duì)象詳細(xì)說(shuō)明原因.如果你正在使用jQuery,那么你將會(huì)丟失你的error()回調(diào),然后你可以解析你的對(duì)象.
$.ajax({
data: {},
dataType: 'html',
success: function(data) {
// do whatever here
},
type: 'POST',
url: 'myserver.com',
error: function(XMLHttpRequest, textStatus, errorThrown) {
// XMLHttpRequest.responseText has your json string
// XMLHttpRequest.status has the 401 status code
if (XMLHttpRequest.status === 401) {
location.href = 'login.php';
}
}
});
我不熟悉PHP,但這應(yīng)該適用于任何環(huán)境.您可能必須禁止任何自動(dòng)登錄表單重定向.在asp.net mvc中,框架將看到401并將默認(rèn)登錄表單推回,狀態(tài)為200.
總結(jié)
以上是生活随笔為你收集整理的php处理ajax post请求超时,php – 如何处理AJAX请求中的会话超时的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: sqldeveloper mysql迁移
- 下一篇: 获取天气html,使用htmlparse