我尝试使用下面包含的两种不同方法。第一个专门使用JavaScript,第二个方法使用jQuery。两者都给出了相同的结果,即它在Firefox中运行良好,但在" http.send()"在Chrome和Internet Explorer 11中。最后,我尝试添加' chrome.exe" --allow-file-access-from-files',但没有任何作用。 Chrome和IE是否过于安全无法运行?欢迎任何建议。
// This function checks to see if the file really exists and returns TRUE if it does.
function urlExists(url) {
var http = new XMLHttpRequest();
try {
http.open('HEAD', url, false);
http.send();
} catch (err) {
silenterror = err;
return false;
}
return http.status === 200;
}

// This function checks to see if the file really exists and returns TRUE if it does.
function urlExists(testUrl) {
var http = jQuery.ajax({
type : "HEAD", //Not get
url : testUrl,
async: false
});
return http.status === 200;
}