mercredi 30 septembre 2015

Checking existance of a file on web server using server-side Javascript

I am generating html code using JavaScript on a web server and the html contains an object that has an id "ImageID" and a src parameters pointing to "Picture1.jpg".

I want to refresh the web page every 5 seconds and use Javascript to generate a new file path using incrementing numbers to say "Picture2.jpg" or "Picture3.jpg" but I want to use the Javascript to check whether such a new file name exists on the server before trying to refresh the img object using

document.getElementById("ImageID").src="Picture2.jpg";

How can server-side JavaScript be used to test the existence of a particular server-side file?

Is these a simple FileExists() method or does the object returned by document.getElementById(ImageName) have to be queried somehow to find out if it successfully found the file or not.

Thanks everyone.

Aucun commentaire:

Enregistrer un commentaire