jQuery bug repeating function on error
Updated Question:
JQuery animation repeats over and over if it encounters an error. Having a return or return false doesn't stop the animation from repeating. What would be the best practice to fix this error? Thanks.
<div id="label"> FADE OUT </div> <script type="text/javascript"> $(function() { $("#label") .animate( {opacity: 0}, 1000, function() { throw new Error("Some error!"); } ); }); </script>
Original Question:
Not sure why this is but after using jQuery for sometime (actually before it became mainstream) I still don't understand why certain functions will keep repeating when it encounters an error.
Example: - Make an ajax call and if the callback encounters an error the ajax call will keep calling the callback. This results in hundreds of errors in the firebug console.
- Even if you use .trigger(event) if the event you trigger has code that enc开发者_运维问答ounters an error jQuery keeps triggering the event over & over.
*I've tried using a try-catch and having a return, or even return false ... but it still doesn't stop jQuery from repeating the event over and over.
My question is 1.) How to stop it? and 2.) I'm very curious as to why this is happening if any one knows.
Thanks!
What do you mean repeating 'over and over'? If I make a handler like so:
$('a').click( function() { throw 'oops'; } );
... are you expecting that on the first click you get an error and then after that it stops calling the handler ...?
精彩评论