samedi 28 mars 2015

jQuery: Get detail of image loading error

I have a javascript that calls a server-side script (PHP) that serves up requested images. There are parameters passed in for the user and image key.


If the requested image does not exist I respond with a 404 error. If the image exists but the user does not have rights to access it, I respond with a 403 error.


Here's a simplified code example...





$img.error(function () {
alert("Image not known or access denied.");
})
.attr("src", "getimg.php?key=horse&user=fred");



I'd like to give a different message depending on whether the problem is with the image key, or whether it is that the user does not have access.


Is there some way that I can either access the HTTP error code returned, or the text returned within the response?


Aucun commentaire:

Enregistrer un commentaire