Reputation: 71
In my project, I want to download file and this file will be deleted after download.
I had set async:false in first ajax to confirm that downloading file is finish.
//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){
}
});
But unlucky, delete is always before download as it needs time to download, but deleting file just for a second.
So I always get messages about "can not find file in server".
Is there a return value for window.location=delFile
after downloading file successfully?
Upvotes: 0
Views: 1204
Reputation: 6546
async: false
is deprecated. You can delete your file in success
callback. like below
$.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) {}
});
}
});
Upvotes: 1