Dear All
Can you please tell me how to check wheather file exists on server using javascript
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mayur GujrathiPosted Apr 10, 2012, 2:12 AM
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;
}
MuthuMari MPosted Apr 9, 2012, 10:07 AM
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