[英]Check image exists on server
当我使用此功能验证是否在服务器上上传了图像时,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)
这是什么意思,这是正常与否?
我个人将创建一个new Image()
,将其src
设置为目标图像,并设置onload
处理程序以执行某些操作(如果存在),以及设置onerror
处理程序以执行某些操作(如果不存在)。
您仍然会在控制台中收到404
错误,但这很好-我们正在处理错误,因为我们希望可能会发生错误!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.