Dear All
Can you please tell me how to check wheather file exists on server using javascript
How to check file exists on server using javascript
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
MuthuMari MRank #5,738 · 288 reputationPosted Apr 9, 2012, 6:07 AM EDT
pls refer this url
http://stackoverflow.com/questions/3646914/how-do-i-check-if-file-exists-in-jquery-or-javascript
thanks.
If this post is useful then mark it as "Accepted Answer
Mayur GujrathiRank #666 · 3.6K reputationPosted Apr 9, 2012, 10:12 PM EDT
function isFile(str)
{
var O = AJ();
// alert(O);
if (!O) return false;
try
{
O.open("HEAD", str, false);
O.send(null);
// alert(O.status);
return (O.status == 200) ? true : false;
}
catch (er)
{
// alert("err");
return false;
}
}
function AJ()
{
var obj;
if (window.XMLHttpRequest)
{
obj = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
try
{
obj = new ActiveXObject('MSXML2.XMLHTTP.3.0');
}
catch (er)
{
// alert("err");
obj = false;
}
}
//alert(obj);
return obj;
}