简单,只需使用HEAD方法,而不是GET或POST:
function UrlExists(url, callback){ var http = new XMLHttpRequest(); http.open('HEAD', url); http.onreadystatechange = function() { if (this.readyState == this.DONE) { callback(this.status != 404); } }; http.send();}这只是展示如何使用HEAD方法的简短示例。生产代码可能需要针对不同的结果状态(成功,失败,超时)更细粒度的回调,并可能使用不同的事件处理程序(
onload,
onerror而
ontimeout不是
onreadystatechange)。



