📄 5-24.html
字号:
<HTML>
<HEAD>
<TITLE> AJAX深入浅出--代码5-24</TITLE>
</HEAD>
<BODY>
<TEXTAREA id="allHeadText" ROWS="6" COLS="40"></TEXTAREA><INPUT TYPE="button" value="读所有头部" onclick="readAllHead();">
<BR><BR>
读取该头部:<SELECT id="headName">
<OPTION>Pragma</OPTION>
<OPTION>Expires</OPTION>
<OPTION>Cache-Control</OPTION>
<OPTION>Content-Type</OPTION>
<OPTION>Date</OPTION>
<OPTION>Server</OPTION>
</SELECT>
<BR>
<TEXTAREA id="headText" ROWS="5" COLS="40"></TEXTAREA><INPUT TYPE="button" value="读指定头部" onclick="readHead(document.getElementById('headName').options[document.getElementById('headName').selectedIndex].text);">
<BR><BR>
验证该资源:<INPUT TYPE="text" id="sourceUrl" style="width:210"><BR>
<TEXTAREA id="sourceText" ROWS="5" COLS="40"></TEXTAREA><INPUT TYPE="button" value="验证资源是否可用" onclick="validSource(document.getElementById('sourceUrl').value);">
</BODY>
</HTML>
<script language="javascript">
var headHttpRequest = null;//读取头部的XMLHttpRequest对象
//读取所有头部
function readAllHead() {
if(headHttpRequest==null) headHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
headHttpRequest.open("HEAD","http://localhost:8100/index.jsp",false);
headHttpRequest.send(null);
document.getElementById("allHeadText").value=headHttpRequest.getAllResponseHeaders();
}
//读取指定头部
function readHead(head) {
if(headHttpRequest==null) headHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
headHttpRequest.open("HEAD","http://localhost:8100/index.jsp",false);
headHttpRequest.send(null);
document.getElementById("headText").value=headHttpRequest.getResponseHeader(head);
}
//验证指定资源是否可用
function validSource(url) {
if(headHttpRequest==null) headHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
headHttpRequest.open("HEAD",url,false);
headHttpRequest.send(null);
if(headHttpRequest.status==200) {
document.getElementById("sourceText").value="该资源可用!";
} else if(headHttpRequest.status==404) {
document.getElementById("sourceText").value="该资源不可用!";
} else if(headHttpRequest.status==500) {
document.getElementById("sourceText").value="服务器端程序异常!";
} else document.getElementById("sourceText").value="其它未知情况!";
}
</script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -