繁体   English   中英

检查服务器上是否存在映像

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM