Ns_error_not_initialized

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dcostalis
    New Member
    • Feb 2007
    • 5

    Ns_error_not_initialized

    Yes. another one.

    This is not my first httprequest site, but it is only my second. I didn't have any
    issues the first run through. the error produced is:
    Code:
    Error: uncaught exception: 
    [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: http://whathuhstudios.com/westside_dev/ :: sndReq :: line 32"  data: no]
    here is the code that is being excecuted. The startajax() runs from an onclick

    Code:
    var browser = navigator.appName;
    
    function startajax()
    {
    sndReq(document.getElementById('catagorylist').value,'providerlist.php', 'test');
    
    }
    
    function createRequestObject() {
        var ro;
        if(browser == "Microsoft Internet Explorer"){
            ro = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
            ro = new XMLHttpRequest();
        }
        return ro;
    }
    var http = createRequestObject();
    
    
    function sndReq(request, ajax_file, targeturi) {
    	var requesturi = 'ajax/' + ajax_file ;
        document.getElementById(targeturi).innerHTML = requesturi;     
        http.onreadystatechange = new Function(handleResponse(targeturi));
        http.send(null);
    }
    	
    function handleResponse(targeturi) {
        if(http.readyState == 4) {
            var response = http.responseText;
     	    document.getElementById(targeturi).innerHTML = response;     
    	}
    }
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Never use browser detection, always use object detection.
    Use something similar to the following instead:
    Code:
    function GetXmlHttpObject() {
      var xmlhttp;
      if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
        xmlhttp = new XMLHttpRequest();
        //if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/xml');
      } else if (window.ActiveXObject) { // IE
          try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) {
              try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
              } catch (e) {}
          }
      }
      if (!xmlhttp) {
        alert('Cannot create an XMLHTTP instance');
        return false;
      }
      return xmlhttp;
    }

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      You also need to use the open method to send a request to the server:
      Code:
      xmlHttp.open("GET",requesturi,true);

      Comment

      • dcostalis
        New Member
        • Feb 2007
        • 5

        #4
        Oh my GOD I'm an idiot. I had this script working on another site, and i must have deleted the line and not noticed it... no wonder the readystate never changed.

        Thank you for your help, I appreciate it very much.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          No problem. You're welcome.

          Comment

          Working...