簡體   English   中英

如何確定文件是否成功下載

[英]How to make sure if a file is downloaded successfully

在我的項目中,我想下載文件,下載后該文件將被刪除。

我在第一個ajax中設置了async:false,以確認下載文件已完成。

 //this is download file code:
 $.ajax({
        dataType:'json',
        type:'POST',
        async: false,
        data:{files:files},
        url:'oat.php',
        success:function(data){
            delFile=data.name;
            alert(delFile);
            window.location=delFile;
        }
    });

    //this is delete file code:
    $.ajax({
           type:'POST',
           data:{delFile:delFile},
           url:'delFileoat.php',
           success:function(data){
            }
        });

但不幸的是,刪除總是在下載之前進行,因為它需要一些時間來下載,但刪除文件僅需一秒鍾。

因此,我總是收到有關“在服務器中找不到文件”的消息。

成功下載文件后, window.location=delFile是否有返回值?

async: false使用async: false 您可以在success回調中刪除文件。 像下面

$.ajax({
  dataType: 'json',
  type: 'POST',
  data: {
    files: files
  },
  url: 'oat.php',
  success: function(data) {
    // do your stuff
    $.ajax({
      type: 'POST',
      data: {
        delFile: delFile
      },
      url: 'delFileoat.php',
      success: function(data) {}
    });
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM