当我使用此功能验证是服务器上的图像上传时,safari调试器显示错误
function UrlExists(url)
{
var http = new XMLHttpRequest();
http.open('HEAD', url, false);
http.send();
return http.status!=404;
}
[Error] Failed to load resource: the server responded with a status of 404 (Not Found)
send ([native code], line 0)
UrlExists (myfunction.js, line 32)
(anonymous function) (user_dialog_list.php, line 354)
c (jquery.js, line 4)
fireWith (jquery.js, line 4)
k (jquery.js, line 6)
r (jquery.js, line 6)
这是什么意思,这是否正常?
答案 0 :(得分:0)
就个人而言,我会创建一个new Image()
,将其src
设置为目标图像,并设置onload
处理程序以执行某些操作(如果确实存在),以及{{1}处理程序如果不做的话就做某事。
您仍会在控制台中收到onerror
错误,但这很好 - 我们正在处理错误,因为我们预计可能会发生错误!