2 Replies Latest reply on Mar 9, 2011 1:13 AM by Robert Gary

    Proper A4J.AJAX.onError handling

    Robert Gary Newbie

      I've found that I receive 5xx errors in my onError handler for two reasons...

       

      1) Connectivity error to server

      2) On FireFox if a user navigates away from the current page or another action reposts the same page (I assume FF disconnects the socket to the server as part of unloading the javascript code thus generating this error).

       

      Its very annoying to users if I display an error for case #2. Its also confusing to not present an error for case #1. So I've written code that does two things. 1) Do not actually show the alert message for 5 seconds in case the javascript is in the process of unloading. 2) If the javascript code is still there after 5 seconds, ensure we're looking at the same document.

       

      function showAjaxError(req, status, message)

      {

          if ( document.documentElement != req._documentElement)

          {

              return;

          }

       

          alert("Connection to server lost.\n" +

                "Ensure server is running\n\nDetail status: " + status + " " + message);

       

       

      }

       

      A4J.AJAX.onError = function(req, status, message){

       

          //Delay this. We also get this error when the page is unloading. This delay should unload itself if

          //its a reload

          setTimeout(function(){showAjaxError(req,status,message);}, 5000);

      };

       

       

      Comments?? Opinions on this solution????

       

      -Robert

        • 1. Proper A4J.AJAX.onError handling
          Rocky S Master

          2) On FireFox if a user navigates away from the current page or another action reposts the same page (I assume FF disconnects the socket to the server as part of unloading the javascript code thus generating this error).

           

           

          If the user navigates away from the current page, bascially you should have session timeout mechanisim

           

          Another action reposts the same page, it would be very rare chance to happen. Are you using Seam, if yes Seam will help you automatically take care of mutliple sessions established thru mulitple browsers by the same user.

           

          Your code seems to be good, as long as you have a test case to test your functionality.

          • 2. Proper A4J.AJAX.onError handling
            Robert Gary Newbie

            At least in RF 3.3.3 in FireFox if you click away from a page during a Richfaces Ajax query (i.e. its waiting for the server when you click away) you get a 599 error. It may have been different when I was using RF 3.1

             

            -Robert