SJamG
09-06-2011, 02:54 PM
Hello,
Really need some help with this code i found online to check to see if a page exists. i am kind of new to Javascript and to have this working would really help me out!
Here is the code :
<script language="javascript">
var url = "http://www.google.com";
checkUrl(url);
function checkUrl(url) {
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest;
} else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHttp");
}
if (request) {
request.open('GET', url, true);
if (request.status == 200) { //FAILING ON THIS LINE ("Unspecified Error")
alert ("File does exist");
}
}
alert("File does not exist");
}</script>
It seems to be failing on the .status line and it returns an Unspecified Error in the debugger.
I am using IE9 if that makes any difference. I have also tried amending the IF statement to include the readyState == 4, i dont get the error, but it doesn't work as planned.
Really appreciate any help.
SJG
Really need some help with this code i found online to check to see if a page exists. i am kind of new to Javascript and to have this working would really help me out!
Here is the code :
<script language="javascript">
var url = "http://www.google.com";
checkUrl(url);
function checkUrl(url) {
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest;
} else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHttp");
}
if (request) {
request.open('GET', url, true);
if (request.status == 200) { //FAILING ON THIS LINE ("Unspecified Error")
alert ("File does exist");
}
}
alert("File does not exist");
}</script>
It seems to be failing on the .status line and it returns an Unspecified Error in the debugger.
I am using IE9 if that makes any difference. I have also tried amending the IF statement to include the readyState == 4, i dont get the error, but it doesn't work as planned.
Really appreciate any help.
SJG