Hey,
I bit the bullet and needed to use ajax to check if a page exists, as I am writing a link manager for someone.
[code=php]
var fail = false;
var http_request = false;
var url = document.getElementsByName(‘txtURL’)[0].value;
function check_link(){
//AJAX it!
if (window.XMLHttpRequest){
http_request = new XMLHttpRequest(); //set the request
http_request.onreadystatechange = is_valid_url; //function to call on each set
http_request.open(“GET”, url, true); //set the page to request
http_request.send(null); //initialize the request
}
//ActiveX – can we say IE?
else if(window.ActiveXObject){
//Create our RequestObject
http_request = new ActiveXObject(“Microsoft.XMLHTTP”);
if(http_request){
http_request.onreadystatechange = is_valid_url //function to call on each step
http_request.open(“GET”, url, false); //set the page to request
http_request.send(null); //initialize the request
}
}
if(fail){
alert(‘failed’);
return false;
}else{
alert(‘passed’);
return true;
}
}
function is_valid_url(){
if (http_request.readyState == 4){
if(http_request.status != 200)
fail = true;
else
fail = false;
return;
}
}
ok, that is the basis of my code.
If I check readyState, I get on error of ‘Access Denied’ on the line that sets the function to the onreadystatechange.
If I remove the check for readyState, I get an ‘Unspecified Error’ in the is_valid_url function when it tries to check http_request.status.
Any help appreciated,
CM!