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

  • SEARCH
  • Home
  • 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 6581219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:07:31+00:00 2026-05-25T16:07:31+00:00

Basically just looking to see if a particular txt file exists on the server,

  • 0

Basically just looking to see if a particular txt file exists on the server, and if so, do further processing; however, I don’t think my recursion is correct, so can someone offer a few pointers – here’s what I have:

function fileExists(filename) {
    $.ajax({
        type: 'HEAD',
        url: 'http://www.example.com/system/'+filename+'.txt',
        success: function() {
            // Further processing if file exists
        },  
        error: function() {
            // File does not exists, run through function again-
            return arguments.callee(filename);
        }
    });
}

It’s pretty basic, there’s some processing before hand that actually creates the file; however the issue is it’s FTP-ed up to our domain, which means timing can vary by a few seconds, so basically I just want it to recheck until it sees that the file exists. I’ll modify it a little afterwards to control the stack, possibly setting a timeout of half a second or something, but I’m not that great with javascript, so I need a few pointers to make this recursive. Any help is GREATLY appreciated.

  • 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-25T16:07:32+00:00Added an answer on May 25, 2026 at 4:07 pm

    the issue is when you try to call fileExists again via arguments.callee(fileName), the scope of the error method isn’t what you think it is.

    Just call fileExists.

    The other you are going to have is that if your server is quick, you are going to be firing a ton of requests. You probably want to wait some time between requests. So make error contain

    setTimeout(function(){
        console.log('trying again....'); // this won't work in IE, I *think*
        fileExists(filename);
    }, 1000); // try again in a second
    

    Finally, you should realize that the error callback only gets invoked if the server returns a 500. The 500 code usually means there was an error on your server. If a file doesn’t exist, you should probably return json to indicate the file doesn’t exist, and handle that case in your success callback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically just looking to see if you can capture an image from the webcam
I'm looking for a method in Ruby which is basically this: io.ready_for_read? I just
I basically want to make things easier by just looping LinkButtons instead of making
I'm writing an application that is basically just a preferences dialog, much like the
One simple method I've used in the past is basically just creating a second
So I have site list on certain pages that basically just have links to
I have an MFC application. It is basically just copying files from one drive
I've used CCK to create a 'Travel Offer' content-type which basically just lists the
Is there an easy (therefore quick) way to accomplish this? Basically just take some
Basically I just need the id of the record on the first form so

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.