Error: uncaught exception in Firefox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xhunter
    New Member
    • May 2007
    • 42

    Error: uncaught exception in Firefox

    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 :
    [CODE=javascript]
    var requestTimer = setTimeout(func tion() {
    xmlHttp.send(po st);
    }, 10000);
    xmlHttp.onready statechange=fun ction () {.....;}

    xmlHttp.open('P OST',url,true);
    xmlHttp.setRequ estHeader("Cont ent-type", "applicatio n/x-www-form-urlencoded");
    xmlHttp.setRequ estHeader("Cont ent-length", post.length);
    xmlHttp.setRequ estHeader("Conn ection", "close");
    xmlHttp.send(po st);

    [/CODE]

    but when the timeout goes into action I get (even though it works and I get the request resent):

    Error: uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILU RE) [nsIXMLHttpReque st.send]" nsresult: "0x80004005 (NS_ERROR_FAILU RE)" location: "JS frame ::

    I know the issue is somehow related to using xmlHttp.send twice,
    but I can't think of anyways to make this work.[CODE]
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Open and send the request again. Put the Ajax call in a function and call that in setTimeout.

    Comment

    • xhunter
      New Member
      • May 2007
      • 42

      #3
      thanks
      I did try something like that before I post here, but the same problem,

      I finally did it by aborting it and doing it all over again, but now I get a new error,
      here is the sample code:

      [CODE=javascript]
      var xmlHttp=p211Get XmlHttpObject() ;
      var requestTimer = setTimeout(func tion() {
      xmlHttp.abort() ;
      xmlHttp=p211Get XmlHttpObject() ;
      xmlHttp.onready statechange=fun ction () {p211state(xmlH ttp,divid,info, onload,requestT imer);}
      reqfunc();
      }, 10000);

      xmlHttp.onready statechange=fun ction () {p211state(xmlH ttp,divid,info, onload,requestT imer);}

      var reqfunc= function() {
      xmlHttp.open('P OST',url,true);
      xmlHttp.setRequ estHeader("Cont ent-type", "applicatio n/x-www-form-urlencoded");
      xmlHttp.setRequ estHeader("Cont ent-length", post.length);
      xmlHttp.setRequ estHeader("Conn ection", "close");
      xmlHttp.send(po st);
      }
      reqfunc();
      [/CODE]


      now I get :

      Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_A VAILABLE) [nsIXMLHttpReque st.status]" nsresult: "0x80040111 (NS_ERROR_NOT_A VAILABLE)" location: "JS frame :: http://.............js :: p211state :: line 59" data: no]
      Source File: http://...............js
      Line: 59
      referring to this line in my code:

      Code:
      if(xmlHttp.status==200)
      in

      Code:
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
      clearTimeout(requestTimer); 
      if(xmlHttp.status==200) 
      {......}}

      even though everything is perfectly working.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by xhunter
        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.
        Don't do it this way. Check the status from the response. If it fails, then make another request.

        Comment

        • xhunter
          New Member
          • May 2007
          • 42

          #5
          Originally posted by acoder
          Don't do it this way. Check the status from the response. If it fails, then make another request.
          I am not quite sure what you mean?

          sometime due to network issues.. or else the readyState remains 2 and doesn't continue, so I want to retry the action if the timeout was not cleared in readyState==4.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by xhunter
            sometime due to network issues.. or else the readyState remains 2 and doesn't continue, so I want to retry the action if the timeout was not cleared in readyState==4.
            Ok, so instead of just aborting, first check that the ready state is not complete. That's possibly what is causing the exception.

            Comment

            • xhunter
              New Member
              • May 2007
              • 42

              #7
              thanks for all the help,

              I am still not sure about it,

              what the script does is to set a timeout which is cleared when readystate is 4 that mean sort of checking the readystate, so if there is an issue in completion of the request before this state, the timeout function starts working.

              so in a normal case, there is no errors at all, only when there is a problem.

              (I simulate a problem by limiting the speed of my browser so after let's say 10 sec the request would still not be complete (state 4) and so that triggers the timeout to abort the previous request and make a new one,
              this way I can simulate if there is an issue before readysate 4 is reached, otherwise it works fine when there is no issue cause the timeout is not executed)

              what I still don't understand is why the new error is referring to the status check?????

              and more strange is, that it works fine as it is expected, it only causes an error with no effects on the loading.

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Show the rest of your p211state function.

                Comment

                • xhunter
                  New Member
                  • May 2007
                  • 42

                  #9
                  ok,

                  here it goes :

                  [CODE=javascript]

                  var xmlHttp=p211Get XmlHttpObject() ;
                  if (xmlHttp==null) {alert ("Browser does not support HTTP Request");retur n;}
                  var requestTimer = setTimeout(func tion() {
                  xmlHttp.abort() ;
                  document.getEle mentById(divid) .innerHTML='Ret rying....';
                  xmlHttp=p211Get XmlHttpObject() ;
                  xmlHttp.onready statechange=fun ction () {p211state(xmlH ttp,divid,info, onload,requestT imer);}
                  reqfunc();
                  }, 10000);
                  xmlHttp.onready statechange=fun ction () {p211state(xmlH ttp,divid,info, onload,requestT imer);}


                  if(method.toUpp erCase()=='GET' ) {
                  var reqfunc= function() {
                  xmlHttp.open('G ET',url,true);
                  xmlHttp.send(nu ll);
                  }}
                  else if(method.toUpp erCase()=='POST ') {
                  var reqfunc= function() {
                  xmlHttp.open('P OST',url,true);
                  xmlHttp.setRequ estHeader("Cont ent-type", "applicatio n/x-www-form-urlencoded");
                  xmlHttp.setRequ estHeader("Cont ent-length", post.length);
                  xmlHttp.setRequ estHeader("Conn ection", "close");
                  xmlHttp.send(po st);
                  }}
                  reqfunc();

                  function p211state(xmlHt tp,p211pidd,inf o,onload,reques tTimer) {
                  if (xmlHttp.readyS tate == 1 ) {..........}
                  if (xmlHttp.readyS tate == 2 ) {..........}
                  if (xmlHttp.readyS tate==4 || xmlHttp.readySt ate=="complete" ){
                  clearTimeout(re questTimer);
                  if(xmlHttp.stat us==200) {
                  document.getEle mentById(p211pi dd).innerHTML=x mlHttp.response Text; } else {document.getEl ementById(p211p idd).innerHTML= "There was a problem retrieving the data: " + xmlHttp.status + " " + xmlHttp.statusT ext + "."; }
                  ............... ..}}
                  }

                  [/CODE]

                  Comment

                  • Rossi Andrea

                    #10
                    uncaught exception in firefox

                    I've got the same problem..In internet explorer my program works perfectly, but in Firefox try this exception:
                    -----
                    uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILU RE) [nsIXMLHttpReque st.send]" nsresult: "0x80004005 (NS_ERROR_FAILU RE)" location: "JS frame :: file:///C:/Users/workspace/request.js :: sendRequest :: line 48" data: no]
                    -----
                    My JAVASCRIPT CODE is:
                    Code:
                    function sendRequest(url,params)
                            {                      
                    var http = getXMLHttp();   http.open("GET",url,false);                          http.onreadystatechange=function() {
                                  if (http.readyState==4) {
                                           response = http.responseText;
                                                          }
                                                     };    
                    http.send();   
                    }
                                
                                  
                    function getXMLHttp() {
                                 var xmlhttp = null;
                                    if (window.ActiveXObject) {
                                       if(navigator.userAgent.toLowerCase().indexOf("msie5")!=-1)                  {
                                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                                        } else {
                                 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                                        }
                                      }
                               if(!xmlhttp&&typeof(XMLHttpRequest)!='undefined') {
                                        xmlhttp = new XMLHttpRequest();
                                      }
                                      return xmlhttp;
                                      } 
                    
                    --------
                    
                    And in another js file, there is a function that call:
                    
                    var req = sendRequest(indirizzo,null,"get");
                    What is the problem??
                    Last edited by gits; Oct 15 '10, 10:54 PM. Reason: added code tags

                    Comment

                    Working...