Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 12th, 2012  |  syntax: None  |  size: 0.81 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Firefox doesn't show javascript errors on AJAX 'threads'?
  2. $.ajax({
  3.     type:  'POST',
  4.     ...
  5.     success: function(data) {
  6.         test_fn();
  7.     }
  8. });
  9.        
  10. function test_fn() {
  11.     blah
  12. }
  13.        
  14. $.ajax({
  15.     type:  'POST',
  16.     ...
  17.     success: function(data) {
  18.         test_fn();
  19.     },
  20.     error: function(jqXHR, textStatus, errorThrown){
  21.        // Aw Snap... Check textStatus maybe?
  22.     }
  23. });
  24.        
  25. function wrap(func) {
  26.     return function wrapped() {
  27.         try {
  28.             func.apply(this, arguments);
  29.         }catch(ex) {
  30.             if(console&&console.error) {
  31.                 console.error(ex);
  32.             }else{
  33.                 alert(ex);
  34.             }
  35.         }
  36.     };
  37. }
  38.        
  39. $.ajax({
  40.     ...
  41.     success: wrap(function(data) {
  42.         // Test it by generating an error by calling a number.
  43.         (1)();
  44.     })
  45. });