I\'d like to cancel a .load() operation, when the load() does not return in 5 seconds. If it\'s so I show an error message like \'sorry, no picture loaded\'.
What I
$('#myImage').load(function(){...})
is not a function call to load the image, it is actually shorthand to bind a callback to the onload event.
Therefore, adding a timeout
parameter to the .load() method as suggested in other answers will have no effect.
It think your two options are:
Continue on the path you are
following and do something like
$('#myImage').attr('src', '');
to
cancel the image load after it times
out, or
Find some way to use $.ajax( { ... , timeout: 5000, ...} );
to load
the image instead of letting the
browser do it automatically via the
attribute.