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

XMLHttpRequest Working in FF2.0.0.8 but not NN9???

RMWChaos
100+
P: 137
Bizarro, that's all I can say. Aren't FF2.0.0.8 and NN9 both Mozilla 2 based browsers? So why would the exact same code work in one and not the other? To add insult to injury, it works just fine in IE7 too.

In particular, I'm grabbing a ".txt" file, which you'll see in my code uses innerHTML to display, whereas ".xml" and ".js" files do not. Perhaps not a good way to do it...does NN9 have an issue with innerHTML?

So here's my code for all you code-junkies to peruse:

Expand|Select|Wrap|Line Numbers
  1. function loadData(url)
  2.  
  3.     {
  4.  
  5.     xmlhttp = null;
  6.  
  7.     fileType = url;
  8.  
  9.     /* **** Code for native XHR **** */
  10.  
  11.     if (window.XMLHttpRequest)
  12.  
  13.         {
  14.  
  15.         xmlhttp = new XMLHttpRequest();
  16.  
  17.         }
  18.  
  19.     /* **** Code for MSIE 6.0+ XHR **** */
  20.  
  21.     else if (window.ActiveXObject("Msxml2.XMLHTTP"))
  22.  
  23.         {
  24.  
  25.         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  26.  
  27.         }
  28.  
  29.     /* **** Code for MSIE 5.5+ XHR **** */
  30.  
  31.     else if (window.ActiveXObject("Microsoft.XMLHTTP"))
  32.  
  33.         {
  34.  
  35.         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  36.  
  37.         };
  38.  
  39.     if (xmlhttp != null)
  40.  
  41.         {
  42.  
  43.         xmlhttp.open("GET", url, false);
  44.  
  45.         xmlhttp.onreadystatechange = processData;
  46.  
  47.         xmlhttp.send(null);
  48.  
  49.         }
  50.  
  51.     else
  52.  
  53.         {
  54.  
  55.         alert("We're sorry, but your browser version does not support XMLHTTP / AJAX.");
  56.  
  57.         };
  58.  
  59.     };
  60.  
  61. function processData()
  62.  
  63.     {
  64.  
  65.     /* **** If xmlhttp shows "loaded" **** */
  66.  
  67.     if (xmlhttp.readyState == 4)
  68.  
  69.         {
  70.  
  71.         /* **** If status is "OK" **** */
  72.  
  73.         if (xmlhttp.status == 200)
  74.  
  75.             {
  76.  
  77.             var responseText = xmlhttp.responseText;
  78.  
  79.             var responseXML = xmlhttp.responseXML;
  80.  
  81.             /* **** If target is a text document **** */
  82.  
  83.             if (fileType.lastIndexOf("txt") > -1)
  84.  
  85.                 {
  86.  
  87.                 document.getElementById('content').innerHTML = responseText;
  88.  
  89.                 };
  90.  
  91.             /* **** If target is a xml document **** */
  92.  
  93.             if (fileType.lastIndexOf("xml") > -1)
  94.  
  95.                 {
  96.  
  97.                 // xml parse code here for responseXML
  98.  
  99.                 };
  100.  
  101.             /* **** If target is a javascript file **** */
  102.  
  103.             if (fileType.lastIndexOf("js") > -1)
  104.  
  105.                 {
  106.  
  107.                 /* **** If MSIE **** */
  108.  
  109.                 if (window.execScript)
  110.  
  111.                     {
  112.  
  113.                     execScript(responseText, "javascript");
  114.  
  115.                     return null;
  116.  
  117.                     }
  118.  
  119.                 /* **** If Mozilla, FireFox, Netscape, etc. **** */
  120.  
  121.                 else if (window.eval)
  122.  
  123.                     {
  124.  
  125.                     eval(responseText);
  126.  
  127.                     }
  128.  
  129.                 /* **** If Safari or other **** */
  130.  
  131.                 else
  132.  
  133.                     {
  134.  
  135.                     setTimeout(responseText, 0);
  136.  
  137.                     };
  138.  
  139.                 };
  140.  
  141.             }
  142.  
  143.         else
  144.  
  145.             {
  146.  
  147.             alert("Problem retrieving data:\n" + xmlhttp.status + "\n" + xmlhttp.statusText);
  148.  
  149.             };
  150.  
  151.         };
  152.  
  153.     };
  154.  
Oct 23 '07 #1
Share this Question
Share on Google+
7 Replies


acoder
Expert Mod 15k+
P: 16,027
In particular, I'm grabbing a ".txt" file, which you'll see in my code uses innerHTML to display, whereas ".xml" and ".js" files do not. Perhaps not a good way to do it...does NN9 have an issue with innerHTML?
So do the XML and JS parts work?
Oct 24 '07 #2

RMWChaos
100+
P: 137
So do the XML and JS parts work?
Apparently, no. It seems that XMLHttpRequest is not working at all in NN9 for me. Works perfectly in IE7 and FF2.0.0.8 though. Weird. I know my onclick="" is working because I tested it with alert("Test Message"); and it came right up. Javascript is definitely working as well because my login script is functioning.

Any ideas? Isn't NN9 native XHR (i.e. xmlhttp = new XMLHttpRequest();)?
Oct 24 '07 #3

drhowarddrfine
Expert 5K+
P: 7,435
Aren't FF2.0.0.8 and NN9 both Mozilla 2 based browsers?
NN and FF are based on gecko, the rendering engine. Mozilla is another browser based on gecko.
Oct 24 '07 #4

RMWChaos
100+
P: 137
Okay, gecko then. If they are both gecko-based, then wtf is the problem with NN? =D
Oct 24 '07 #5

acoder
Expert Mod 15k+
P: 16,027
Apparently, no. It seems that XMLHttpRequest is not working at all in NN9 for me. Works perfectly in IE7 and FF2.0.0.8 though. Weird. I know my onclick="" is working because I tested it with alert("Test Message"); and it came right up. Javascript is definitely working as well because my login script is functioning.

Any ideas? Isn't NN9 native XHR (i.e. xmlhttp = new XMLHttpRequest();)?
The XMLHttpRequest object works fine in NN9 for me.

Try some test links, e.g. this one.
Oct 25 '07 #6

RMWChaos
100+
P: 137
acoder,

And here you are again helping me out! Yes, I tested that in NN and it worked as it always has (that's one the of the sites that I've been learning how to code from, including XHR).

So something is goofy in my code. I've noticed that sometimes my code doesn't work for no reason I can discern, and if I retype it exactly as I have it coded, the code then works. Go figure. So I am going to try that today.

I code mostly in notepad. Is there anything about notepad encoding that could cause this type of hiccup? I can always code in WordPad instead, and I have MS Visual Web Developer 2008 Express Edition, which would probably help me catch errors more often. Sigh. I guess I just need to get in the habit of using it. Old habits (old BASIC & COBOL coder here) die hard, I suppose.

Thanks yet again!
Oct 25 '07 #7

drhowarddrfine
Expert 5K+
P: 7,435
I code mostly in notepad. Is there anything about notepad encoding that could cause this type of hiccup?
I don't recall if Notepad can save in utf8? Is it possible the BOM is involved?
I can always code in WordPad instead,
Ack! Don't do that!
I have MS Visual Web Developer 2008 Express Edition, which would probably help me catch errors more often. Sigh. I guess I just need to get in the habit of using it.
Sometimes more time is spend trying to figure out the tools than coding. Look into Notepad++. I liked it much better but I don't use Windows anymore.
Oct 25 '07 #8

Post your reply

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