我正在使用 jquery 表单插件进行 ajax 调用并通过 ajax 上传文件,因为我们需要支持不支持 ajax 级别 2 的 IE8
由于服务器需要一些时间来处理文件,我正在考虑异步进行。
我想知道有没有办法使用 ajax 提交我的表单,仅用于上传/发送文件而不等待响应。
我希望 ajax 发送文件然后关闭连接而不等待服务器的响应,因为它可能需要 12 到 15 分钟。它应该只显示一条消息,说明文件已上传。
下面是我的代码,但它不能通过删除“成功”参数来工作
function validate()
{
var file = $("#file").val();
if(!file || file == '' || file == null)
{
document.getElementById("outdata").innerHTML="Please select a file";
return false;
}
var options = {
target: '#outdata', //Div tag where content info will be loaded in
url:'lookup_process.php',
async:true,
beforeSubmit: function() {
$('#uploader').html('<img src="/images/ajax-loader.gif" />'); //Including a preloader, it loads into the div tag with id uploader
$('input[type=submit]').attr('disabled', true);
$('input[type=reset]').attr('disabled', true);
},
timeout = 120000,
success: function() {
//Here code can be included that needs to be performed if Ajax request was successful
$('#uploader').html('');
$('input[type=submit]').attr('disabled', false);
$('input[type=reset]').attr('disabled', false);
},
error: function(jqXHR, textStatus){
if(textStatus == 'timeout')
{
$('#uploader').html('');
$('input[type=submit]').attr('disabled', false);
$('input[type=reset]').attr('disabled', false);
}
}
};
$('#credit').ajaxSubmit(options);
$('#uploader').html('');
$('input[type=submit]').attr('disabled', false);
$('input[type=reset]').attr('disabled', false);
return false;
}