jon*_*ony 0 javascript xmlhttprequest
我正在使用此功能来检查网页是否存在.为此,我正在检查它是否有标题.但我总是得到404,即使有一个空白的网址..我在这里做错了什么?
var xmlhttp;
function checkURL(url){
xmlhttp=null; // initialize the request object
// All the browsers except for the old IE
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
xmlhttp.onreadystatechange=xmlhttpChange
xmlhttp.open("HEAD",url,true)
xmlhttp.send(null)
}
// old IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
if (xmlhttp)
{
xmlhttp.onreadystatechange=xmlhttpChange
xmlhttp.open("HEAD",url,true)
xmlhttp.send();
}
}
}
function xmlhttpChange()
{
// if loaded
if (xmlhttp.readyState==4)
{
// if head exists "OK"
if (xmlhttp.status==200)
{
alert('URL exists')
}
else
{
alert("Status is "+xmlhttp.status)
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
336 次 |
| 最近记录: |