Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: testing for 404
11-05-2012, 12:18 PM #1
- Join Date
- May 2008
- Milton Keynes
- Thanked 0 Times in 0 Posts
testing for 404
Could I do this using Ajax? I am not really much of a client side developer and I am in a position where I have to learn some bits.
I am developing a help system where when a button is clicked a light box opens up an external help file
(it has to be external due to the server architecture and layout, please I have gone into this enough...)
Anyway the gist is this, if I perform a request and the page is not found I want a 'page not ready' page to be displayed instead, and the best way i can find round this is if the page returns a 404. So if I get this 404 I can call the default page instead.
I really am not looking for code examples (yet!) as I want to be able to try this out myself. But I need to know is it is possible that on a page button click can I discover if the page requested actually exists or not?
11-06-2012, 07:57 AM #2
- Join Date
- Jan 2010
- Behind the Wall
- Thanked 370 Times in 366 Posts
yes, you can do that with AJAX. there are 2 principal ways to do it:
- only check for the file: make a HEAD request (like GET, only it asks for headers). check if the status property is 404.
- make a regular file request. check if the status property is 404.
The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.André Behrens, NY Times Software Developer