Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:50:51+00:00 2026-05-26T00:50:51+00:00

I try to make a recursive function to delete files using jQuery and ajax

  • 0

I try to make a recursive function to delete files using jQuery and ajax to show the status of the process. The problem is, the first time the function is executed (index 0) everything is fine and the “output” is “1594.jpg”. But when the index is incremented to 1, it’s the second caracter of the chain filesToDelete, ‘5’, then ‘9’, and so on.

filesToDelete = new Array();
filesToDelete = '1594.jpg,my.png,test.ogg,Song.mp3,Apple_4S.mov,An App.exe';
filesToDelete = filesToDelete.split(',');

function ajaxDelete(itemList, cpt) {
    var tempItemList = itemList;

    //If cpt is not initialized, initialize it, make sure it's an integer
    if(isNaN(cpt)) cpt = 0*1;

    //If cpt is equal to the array, exit
    if(cpt >= itemList.length) return;

    //Current index
    var curIndex = cpt;
    //The value of the current index
    var current = itemList[curIndex];
    //DEBUG
    console.log('cpt:'+cpt+' index:'+curIndex+'  Value:'+itemList[curIndex]);

    $.ajax({
        url: "deleteFile.php?id="+current,
        beforeSend: function(){
            progressText('Suppression de '+current);
        },
        success: function(data){
            progressText('Suppression...');
            //Index + 1
            cpt++;
            //RECURTION
            setTimeout("ajaxDelete('"+itemList+"', "+cpt+")",1);
        }
    });
}

Any help is welcomed, with explanation if possible..

Thanks !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:50:52+00:00Added an answer on May 26, 2026 at 12:50 am

    Don’t rely on the ajax success method for this, if it fails for whatever reason your stuck.

    You should do an ajax call per file to delete or better yet send the Array of files to the server and let it take care of it.

    for (i = 0; i <= filesToDelete.length; i++)
    {
        // Ajax Call
        $.ajax({
    
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm encountering a big problem when i'm trying to make a recursive search function
When I try to make a very large boolean array using Java, such as:
I'm writing a PHP function that will delete all the files in the directory
I have been using the Learning Java 2nd Edtion book to try make my
I try to make a refund transaction via my django app using code: class
I'll try to make this as straight forward as possible. Currently our team has
I'm fairly new to C# but I will try to make this quick! ;)
If we make any class in VB.NET and try to access its property in
is it possible to make beep in WinCE ? i try and i get
I'm trying to make things simpler. Here is my code: If Threading.Monitor.TryEnter(syncRoot) Then Try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.