I need to load an image by Javascript, but know the difference between a 404 and 500 error if it fails.
I have code to load an image into an 'img' tag like the below:
var img = $('<img />').attr('src', url)
.load(function() {
// Do something.
})
.error(function(ev) {
// What sort of error?
});
In the error() function, I don't seem able to tell whether the error was a 500 or a 404. Is there any way of doing this?
.errorworks at all! It shouldn't. Why does jQuery care that you setting thesrcattribute vs. any other attribute? How/why would it even be able to hook into the HTTP request for an element on the page?