HighDots Forums  

if file exist

Javascript JavaScript language (comp.lang.javascript)


Discuss if file exist in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
zhisol
 
Posts: n/a

Default Re: if file exist - 09-21-2003 , 06:16 AM






Stephen <ssansom (AT) austin (DOT) rr.com> wrote in
newsQ_ab.55358$834.54901 (AT) twister (DOT) austin.rr.com:

Quote:
Send a HEAD request for the "cover.jpg" file. In the handler that is
triggered when the response comes back, check for 200 response code &
then make the image visible at that point.
<script language="JavaScript">
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("HEAD", "cover.jpg", false);
xmlHttp.send();
document.write(xmlHttp.statusText);
</script>

is that correct to see return code on the browser screen?
i see nothing

Quote:
http://jibbering.com/2002/4/httprequest.html
it seems, this web page doesn't exist

--
pozdr
zhisol


Reply With Quote
  #12  
Old   
Stephen
 
Posts: n/a

Default Re: if file exist - 09-21-2003 , 11:39 AM






zhisol wrote:

Quote:
Stephen <ssansom (AT) austin (DOT) rr.com> wrote in
newsQ_ab.55358$834.54901 (AT) twister (DOT) austin.rr.com:


Send a HEAD request for the "cover.jpg" file. In the handler that is
triggered when the response comes back, check for 200 response code &
then make the image visible at that point.


script language="JavaScript"
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("HEAD", "cover.jpg", false);
xmlHttp.send();
document.write(xmlHttp.statusText);
/script

is that correct to see return code on the browser screen?
i see nothing

Should work. Note:

xmlHttp.status should give, e.g., "200"
xmlHttp.statusText should give the associated text, e.g., "OK"

This works for me in my environment, just as you coded it above (except
for substituting an image name I know is on my system).

Server must be configured to allow HEAD requests. Most probably are, but
you'll have to make sure in your case.

You probably also want to check for other possible response codes that
indicate the requested entity is present, e.g., 304.

Regards,
Stephen

Quote:
http://jibbering.com/2002/4/httprequest.html

it seems, this web page doesn't exist



Reply With Quote
  #13  
Old   
Stephen
 
Posts: n/a

Default Re: if file exist - 09-21-2003 , 11:42 AM



zhisol wrote:

Quote:
Stephen <ssansom (AT) austin (DOT) rr.com> wrote in
newsQ_ab.55358$834.54901 (AT) twister (DOT) austin.rr.com:


Send a HEAD request for the "cover.jpg" file. In the handler that is
triggered when the response comes back, check for 200 response code &
then make the image visible at that point.


script language="JavaScript"
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("HEAD", "cover.jpg", false);
xmlHttp.send();
document.write(xmlHttp.statusText);
/script

is that correct to see return code on the browser screen?
i see nothing

Should work. Note:

xmlHttp.status should give, e.g., "200"
xmlHttp.statusText should give the associated text, e.g., "OK"

This works for me in my environment, just as you coded it above (except
for substituting an image name I know is on my system).

Server must be configured to allow HEAD requests. Most probably are, but
you'll have to make sure in your case.

You probably also want to check for other possible response codes that
indicate the requested entity is present, e.g., 304.

Regards,
Stephen

P.S.: need document.close() after the document.write(...)?? Or try
alert instead of document.write()...?
S.

Quote:
http://jibbering.com/2002/4/httprequest.html

it seems, this web page doesn't exist




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.