我正在尝试处理Dropzone
AJAX 文件上传请求的会话超时。我正在通过PHP
中的此if
条件检查请求的类型:
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && !empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')
{
//Here checking if session is set or not
// If session is not set, I am responsing with
http_response_code(401);
}
JS文件
error: function (jqXHR, exception) {
console.log(jqXHR.status); //Here Recieving as error instead of 401
if (jqXHR.status == 401) {
window.location.href="<?php base_url() ?>login";
}
},
但是在Jquery AJAX's
error
函数中,我获得的状态是error
而不是401
。这是Dropzone's
做的吗?拖放区是否返回error
文本?
为什么不尝试 ajaxError() : :注册一个处理程序,以便在 Ajax 请求完成但出现错误时调用。
简单的工作示例:
<script type="text/javascript">
$(document).ready(function () {
$('#click-me').on('click', function() {
$.ajax({
url: 'index.php', //Your ajax call
success: function (response) {
$('#post').html(response.responseText);
}
});
})
});
$( document ).ajaxError(function( event, jqxhr, settings, exception ) {
//This will be called whenever your Ajax request encounters any "401" error response
if ( jqxhr.status== 401 ) {
alert('401 Unauthorized');
}
});
</script>
<a href='#' id='click-me'>FIRE AJAX</a>