这里其实是个tips,目的是判断每张图片是否能正确完整加载了:
(document).ready(function() {
$('img').error(function() {
$.post('ajax-image-error-jquery.php', {
image: $(this).attr('src'),
page: window.location.href
}, function() {
//hide the image?
});
});
});
对于每个图片,监听其中的error事件即可,然后POST到一个PHP去处理,把其中的SRC参数带过去,比如可以发邮件通知:
if(isset($_POST['image']))
{
$to = '[email protected]';
$from = '[email protected]';
$subject = 'Broken Image';
$content = "The website is signaling a broken image!\n\nBroken Image Path: ".stripslashes($_POST['image'])."\n\nReferenced on Page: ".stripslashes($_POST['page']);
$result = mail($to,$subject,$content,'From: '.$from."\r\n");
die($result);
}