如何获取< img>的HTTP状态代码标签 [英] How to get HTTP status code of <img> tags

查看:247
本文介绍了如何获取< img>的HTTP状态代码标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中包含许多根据用户操作生成的服务器端图像。当图像加载成功时,我很高兴,但是当服务器上出现错误时,我必须根据发生的错误采取行动。

I have a page with a lot of images that are generated server-side depending on user actions. And when image loads successfully I'm happy, but when there is an error on the server I have to act according to what an error occurred.

例如:


  • 500代码:做这些东西。

  • 503代码:做那些东西

等等。

所以,我的问题:是吗在img标签错误事件处理程序中获取状态代码的任何方法?

So, my question: is there any way to get status code within "img" tag on-error event handler?

推荐答案

不,无法从 img <的请求中获取HTTP状态/ code> JavaScript中的标记。

No, there is no way to get the HTTP status from a request made by an img tag in JavaScript.

你可以写一个firefox插件,chrome / safari扩展来做到这一点。

You could write a firefox plugin, chrome/safari extension to do that.

另一种方法是使用AJAX加载图像(不使用 img 标签)。您可以从Ajax请求中获取Http状态代码。

An alternative would be using AJAX to load your images (not using img tags). You can get Http Status Codes from Ajax Requests.

这篇关于如何获取&lt; img&gt;的HTTP状态代码标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆