473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

firefox reports uncaught exception NS_ERROR_FAILURE with nsIXMLHttpRequest.send

Plater
7,872 Expert 4TB
I am using the XMLHttpRequest to send a request every 5ish seconds or so.
Everything works fine until I take the server down that the object is trying to retrieve data from.
Then the firefox console keeps racking up these:
Expand|Select|Wrap|Line Numbers
  1. uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIXMLHttpRequest.send]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" 
  2.  
If I turn the server back on, it continues to update it's data just fine. I know a simple solution is to just trap the exception, but I don't think I should have to. There should be something I can do to keep it from generating one in the first place.

Relevant code:
Expand|Select|Wrap|Line Numbers
  1. function createRequestObject() 
  2. {//creates an httprequest object
  3.     var ro;
  4.  
  5.     var browser = navigator.appName;
  6.     if(browser == "Microsoft Internet Explorer"){
  7.         ro = new ActiveXObject("Microsoft.XMLHTTP");
  8.     }else{
  9.         ro = new XMLHttpRequest();
  10.     }
  11.     return ro;
  12. }
  13.  
  14. var http = createRequestObject();
  15. var ourinterval=setInterval("SendUpdate()",5000);
  16.  
  17. function SendUpdate()
  18. {
  19.   http.open('get', '/refresh.cgi?time='+ new Date().getTime());
  20.   http.onreadystatechange = handleSendUpdateReponse;
  21.   http.send(null);
  22. }
  23. function handleSendUpdateReponse()
  24. {
  25.     if(http.readyState == 4)
  26.     {
  27.         var update = new Array();
  28.         if (http.status=="200")
  29.         {
  30.             var response = http.responseText;    
  31.             if (response!="")
  32.             {
  33.               if(response.indexOf('|' != -1)) 
  34.               {
  35.                     update=response.split('|');
  36.                     if (update.length>0)
  37.                   {
  38.                     if (update[1].indexOf("SUCCESS")>-1)
  39.                     {
  40.                         var line=update[1];
  41.  
  42.                         var things=new Array();
  43.                         things=line.split('&');
  44.                         var i;
  45.                         for (i=0;i<things.length;i++)
  46.                         {
  47.                             var nameval=things[i].split('=');
  48.                             if (i>0)
  49.                             {
  50.                                 returnObjById(nameval[0]).innerHTML=nameval[1];
  51.                             }
  52.                         }
  53.                     }//end of found "SUCCESS"
  54.                     }//end of update split("|") to have multiple sections
  55.               }//end of response.indexof("|")
  56.             }//end of response!=""
  57.         }//end of status==200
  58.     }//end of readystate=4
  59. }//end of function
  60.  
Jul 23 '07 #1
2 36659
Plater
7,872 Expert 4TB
Well, turns out that its something firefox just hasn't gotten around to fixing yet:
http://www.fleegix.org/articles/2006..._failure-error

The activeX equiv of XMLHttpRequest does not have this problem, providing a much more usefull notification as "12029" in the http.status
Those error codes can be found here:
http://support.microsoft.com/kb/193625

A lot of people use the XMLHTTPRequest object, why am I the only one doing checking for if the talkbalk host is no longer there?

Here are the changes I made to keep both browsers quiet and happy:
Expand|Select|Wrap|Line Numbers
  1. function SendUpdate()
  2. {
  3.     var action="DATETIME&TEMPERATURE&HUMIDITY&SAMPLESTATE";
  4.     action+="&CHAN1&CHAN2&CHAN3&CHAN4&CHAN5&CHAN6&CHAN7&CHAN8&CHAN9&CHAN10";
  5.     try
  6.     {
  7.         http.open('get', '/refresh.cgi?'+action+'&amp;time='+ new Date().getTime());
  8.       http.onreadystatechange = handleSendUpdateReponse;
  9.       http.send(null);
  10.     }
  11.     catch(error)
  12.     {
  13.         //alert(error);
  14.         returnObjById("SAMPLESTATE").innerHTML="Problem Communicating";
  15.     }
  16.  
  17. }
  18.  
  19. function handleSendUpdateReponse()
  20. {
  21.     if(http.readyState == 4)
  22.     {
  23.         var update = new Array();
  24.         if (http.status=="200")
  25.         {
  26.             var response = http.responseText;    
  27.             if (response!="")
  28.             {
  29.               if(response.indexOf('|' != -1)) 
  30.               {
  31.                     update=response.split('|');
  32.                     if (update.length>0)
  33.                   {
  34.                     if (update[1].indexOf("SUCCESS")>-1)
  35.                     {
  36.                         var line=update[1];
  37.  
  38.                         var things=new Array();
  39.                         things=line.split('&');
  40.                         var i;
  41.                         for (i=0;i<things.length;i++)
  42.                         {
  43.                             var nameval=things[i].split('=');
  44.                             if (i>0)
  45.                             {
  46.                                 returnObjById(nameval[0]).innerHTML=nameval[1];
  47.                             }
  48.                         }
  49.                     }//end of found "SUCCESS"
  50.                     }//end of update split("|") to have multiple sections
  51.               }//end of response.indexof("|")
  52.             }//end of response!=""
  53.         }//end of status==200
  54.         else if(http.status==12029)
  55.         {
  56.             returnObjById("SAMPLESTATE").innerHTML="Problem Communicating";
  57.         }            
  58.     }//end of readystate=4
  59. }//end of function
  60.  
Jul 25 '07 #2
Hi.

I also had a though time figure out a way to make this happen in firefox.
Expand|Select|Wrap|Line Numbers
  1. ////////////////////////////////////////////////////////////////////////////////////////////// 
  2. // firefox reports uncaught exception NS_ERROR_FAILURE with nsIXMLHttpRequest.send
  3. // http://bytes.com/forum/thread681905.html
  4. // http://radio.javaranch.com/pascarello/2006/02/07/1139345471027.html
  5. // http://dev.rubyonrails.org/ticket/4267      
  6. // 
  7. // I needed a way to track server downtime even if the callback does not work when 
  8. // server closes down. Since firefox does not support failover on server downtime I made this object
  9. // where I track errors even if there is no callbacks to track.
  10. // 
  11. //    To use the object from your main app: 
  12. //        failover = new clientFailover();   , create object in seperate "thread" (unsing setInterval)
  13. //        failover.start("fail.php");            , the url where the request is made against as parameter
  14. // object that handles failover between client and server. It pings the server in smal intervals
  15. // and reporttext is generated every 10 seconds. Let me know if anyone comes up with a better solution
  16.  
  17. //////////////////////////////////////////////////////////////////////////////////////////////
  18. function clientFailover(){
  19.        var start,url,frequest;
  20.        var uinterval = 10000;   // set update interval
  21.        var pinterval = 1000;    // set ping interval
  22.        var intervalID = 0;
  23.        var fstatus = false; // true on error, false on normal operation
  24.        var active = false;  // flag on when thread is aktiv
  25.        var errorflag = 0;
  26.  
  27.      // Set error value code, 0 = connection and callback ok, 1 = connection ok but status error
  28.      // 2 = connection ok but page error, 4 = Connection and callback lost
  29.        var setError = function(value){
  30.             errorflag = value;
  31.       };
  32.  
  33.       var getError = function(){
  34.         return errorflag;
  35.       };
  36.  
  37.        // cObject is the XMLHTTPRequest instance
  38.        var cObject = function(){
  39.               var conn = false;
  40.               if (window.XMLHttpRequest){
  41.                   conn = new XMLHttpRequest();
  42.               }else if (window.ActiveXObject){
  43.                   try{
  44.                       conn = new ActiveXObject("Msxml2.XMLHTTP");
  45.                       }catch (e){
  46.                           try{
  47.                           conn = new ActiveXObject("Microsoft.XMLHTTP");
  48.                       }catch (e){
  49.                           conn = false;
  50.                           }
  51.                       }    
  52.                   }
  53.                  return conn;
  54.       }
  55.         // start method, this method is called from the main application
  56.         // Parameter is the URL, This is where the "ping" is making request against
  57.  
  58.         this.start = function(value){
  59.  
  60.             url = value;
  61.             frequest = cObject();
  62.             if (!frequest || !url){
  63.                 return false;
  64.             }else{
  65.  
  66.              ping();
  67.              // set interval for the update info (every 10 second), this should be higher than the ping interval
  68.              setInterval(function(){
  69.                           pushInfo();}
  70.                           ,uinterval);
  71.  
  72.                    return true;
  73.             }
  74.         };
  75.       var pushInfo = function(){
  76.               if (getError() == 4){
  77.                   alert("Server and callback down " + getError());
  78.               }else{
  79.                   alert("Server and callback works " + getError());
  80.               }
  81.       };  
  82.  
  83.       // request (ping) the url page on server. The ping interval is set to one second
  84.      var ping = function(){
  85.  
  86.            intervalID = setInterval(function(){
  87.                 setError(4);
  88.                 frequest.onreadystatechange = check;
  89.                 frequest.open("GET", url, true);
  90.             try{
  91.                 frequest.send(null);
  92.  
  93.             }catch (e){
  94.                 // catch NS_ERROR_NOT_INITZIALIZED
  95.             }
  96.         }, pinterval);
  97.  
  98.       }
  99.      // Check if the request return anything, if so, set status to true meaning that server is down
  100.      var check = function(){
  101.  
  102.         try{
  103.             if (frequest.readyState >= 1){
  104.  
  105.                 if (frequest.status !=200){
  106.  
  107.                     fstatus = true;
  108.                     setError(2);
  109.                 }else{
  110.                     fstatus = false;
  111.                     setError(0);
  112.                 }
  113.             }
  114.         }catch (e){
  115.             setError(4);
  116.             // firefox reports uncaught exception NS_ERROR_FAILURE with nsIXMLHttpRequest.send
  117.             // this failure is catched here
  118.         }    
  119.  
  120.       };
  121.  
  122.  }
  123.  
Jul 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: meaneyedcat | last post by:
When I call addField(), my table appears to be populated correctly with a new row in the table with all the required fields. However, when I call delete row on any new rows that have been created,...
3
by: harishdixit1 | last post by:
Hello friends i m calling a javascript function from toolbar on the web page . but on statement xmlHTTPReq.send( data ); exception occurs. execption is "Component returned failure code:...
5
by: -Lost | last post by:
Error: uncaught exception: " nsresult: "0x80004001 (NS_ERROR_NOT_IMPLEMENTED)" location: "JS frame :: file:///D:/sites/_test/js/iterate_document.htm :: <TOP_LEVEL:: line 15" data: no] Line 15...
2
by: mkoonani | last post by:
Hi, i am getting the following error while using js to communicate between parent and child windows using Firefox browser. Can anyone help me out from this.? MK
2
by: funktacular | last post by:
Hi - I have some javascript that works when I run it from a server, but I need to run it locally. When I try to execute it locally I get the following error: Error: uncaught exception: Permission...
9
by: xhunter | last post by:
Hi, I have written my code to load some content through ajax, which works perfectly, then I thought of adding a timeout to retry the action in case it has failed or something. here is the code...
2
by: josephx | last post by:
Hello, I got some of these errors listed below after executing an HTTP Post MIDlet on CLDC/MIDP platform, "Nokia S40 DP 2.0 SDK 1.1" and "S40 5th Edition SDK Feature Pack 1" and even for S60's...
3
by: friend | last post by:
Error: uncaught exception: " nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: http://manimekalai/VulnMgmt/scanfi/crs_source/vulnupdate/latest.php?vulnerability=2451 ::...
1
by: smohan | last post by:
Hi, I'm very new to perl. I tried to use the perl module in php script, but im getting error <?php $perl = new Perl(); $perl->eval("BEGIN {unshift( @INC, '/opt/otrs');}");...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.