我需要檢查具有Ajax請求的Apache Web服務器的htdocs文件夾中是否存在特定文件。我是Ajax新手。請讓我知道我的方法是否正確。如何檢查Apache Web服務器的htdocs文件夾中是否存在文件
我正在用Javascript編寫以下函數來執行上述操作。
我考慮過的網址是:「http://film.ts」。
function checkURL(url){
var Ajaxhttp;
if (window.XMLHttpRequest){
Ajaxhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
Ajaxhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
Ajaxhttp.open("HEAD",url,true);
Ajaxhttp.onreadystatechange=function(){
if (Ajaxhttp.readyState==4 && Ajaxhttp.status == 200){
data.playoutInfo._playoutUrls[0] = url;
}
else if(Ajaxhttp.status == 404){
data.playoutInfo._playoutUrls[0] = "http://San_Diego_Clip.ts";
}
}
Ajaxhttp.send();
}
對於上述代碼,即使文件不存在,我也會將狀態設置爲200。如果我能通過其他方式實現這一點,請告訴我。
這應該工作得很好。由於配置錯誤,請檢查服務器是否因404錯誤頁面的文本而返回200個狀態。 – Quentin 2013-05-10 12:09:41