我正在尝试处理Dropzone
AJAX Fileupload Requests的会话超时。我正在通过if
中的PHP
条件检查请求的类型:
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
吗? Dropzone是否会返回error
文字?
答案 0 :(得分:1)
为什么不尝试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>