By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,708 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,708 IT Pros & Developers. It's quick & easy.

Ns_error_not_initialized

P: 5
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:
Expand|Select|Wrap|Line Numbers
  1. Error: uncaught exception: 
  2. [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]
  3.  
here is the code that is being excecuted. The startajax() runs from an onclick

Expand|Select|Wrap|Line Numbers
  1. var browser = navigator.appName;
  2.  
  3. function startajax()
  4. {
  5. sndReq(document.getElementById('catagorylist').value,'providerlist.php', 'test');
  6.  
  7. }
  8.  
  9. function createRequestObject() {
  10.     var ro;
  11.     if(browser == "Microsoft Internet Explorer"){
  12.         ro = new ActiveXObject("Microsoft.XMLHTTP");
  13.     }else{
  14.         ro = new XMLHttpRequest();
  15.     }
  16.     return ro;
  17. }
  18. var http = createRequestObject();
  19.  
  20.  
  21. function sndReq(request, ajax_file, targeturi) {
  22.     var requesturi = 'ajax/' + ajax_file ;
  23.     document.getElementById(targeturi).innerHTML = requesturi;     
  24.     http.onreadystatechange = new Function(handleResponse(targeturi));
  25.     http.send(null);
  26. }
  27.  
  28. function handleResponse(targeturi) {
  29.     if(http.readyState == 4) {
  30.         var response = http.responseText;
  31.          document.getElementById(targeturi).innerHTML = response;     
  32.     }
  33. }
Feb 22 '07 #1
Share this Question
Share on Google+
4 Replies


acoder
Expert Mod 15k+
P: 16,027
Never use browser detection, always use object detection.
Use something similar to the following instead:
Expand|Select|Wrap|Line Numbers
  1. function GetXmlHttpObject() {
  2.   var xmlhttp;
  3.   if (window.XMLHttpRequest) { // Mozilla, Safari, Opera...
  4.     xmlhttp = new XMLHttpRequest();
  5.     //if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/xml');
  6.   } else if (window.ActiveXObject) { // IE
  7.       try {
  8.         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  9.       } catch (e) {
  10.           try {
  11.             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  12.           } catch (e) {}
  13.       }
  14.   }
  15.   if (!xmlhttp) {
  16.     alert('Cannot create an XMLHTTP instance');
  17.     return false;
  18.   }
  19.   return xmlhttp;
  20. }
Feb 23 '07 #2

acoder
Expert Mod 15k+
P: 16,027
You also need to use the open method to send a request to the server:
Expand|Select|Wrap|Line Numbers
  1. xmlHttp.open("GET",requesturi,true);
Feb 23 '07 #3

P: 5
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.
Feb 23 '07 #4

acoder
Expert Mod 15k+
P: 16,027
No problem. You're welcome.
Feb 26 '07 #5

Post your reply

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