的HTTP状态代码标签

的HTTP状态代码标签

本文介绍了如何获取& lt; img& gt;的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?

推荐答案

否,无法从JavaScript中 img 标记发出的请求中获取HTTP状态.

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状态代码标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 13:03