gpt4 book ai didi

javascript - DROPZONE - 在文件上传期间处理 AJAX 请求中的 session 超时

转载 作者:搜寻专家 更新时间:2023-10-31 21:26:02 25 4
gpt4 key购买 nike

我正在尝试处理 Dropzone AJAX 文件上传请求的 session 超时。我正在通过 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 的 error 函数中,我得到的状态是 error 而不是 401。这是 Dropzone 的 在做什么? Dropzone 是否返回了 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>

关于javascript - DROPZONE - 在文件上传期间处理 AJAX 请求中的 session 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35986083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com