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

Firefox - 'undefined' error

P: 20
I have a page with table layout which has an AJAX request sent on body onLoad event, during this time the table cells show static text like "Loading". The table cells are later updated with the AJAX response. So when I try to move out of the page once the AJAX request is sent by clicking on a link for exmple, the "Loading" changes to "undefined". I read that innerHTML is not supported by firefox for table cells so i started using div inside the table cell yet no result. However IE and Opera seems to work fine. could anyone please tell me where am going wrong ?? Thanks a ton
May 7 '08 #1
Share this Question
Share on Google+
23 Replies


acoder
Expert Mod 15k+
P: 16,027
Post your code so we can see where the problem might lie.
May 7 '08 #2

P: 20
Thanks for your reply, The ajaxrequest is triggered by the following functions

Expand|Select|Wrap|Line Numbers
  1. function getReportStatus(geturl)
  2. {
  3.    var columnvals;
  4.    var filtervals;
  5.    url = geturl;
  6.    xmlObj = null;
  7.    xmlObj = GetXmlObj(); 
  8. // This function is to choose the right xmlhttp object according to the browser
  9.    xmlObj.onreadystatechange=stateChanged;
  10.    xmlObj.open("GET", url , true);
  11.    xmlObj.send(null);
  12.  
  13. }
  14.  
  15. function stateChanged()
  16.  {
  17.      if (xmlObj.readyState==4 || xmlObj.readyState=="complete")
  18.      {
  19.          data = xmlObj.responseText;
  20.          var data_split = data.split("|");
  21.  
  22.           document.getElementById("citystate").innerHTML= data_split[0];
  23.           document.getElementById("progress").innerHTML = data_split[1];
  24.           document.getElementById("function").innerHTML= data_split[2];
  25.  
  26.          // All the ids above are div element ids which are inside individual <td> elements
  27.  
  28.      }
  29. /*
  30.      else if(xmlObj.readyState==1)
  31.      {
  32.         document.getElementById("citystate").innerHTML = "HEY";
  33.         document.getElementById("progress").innerHTML = "Loading";
  34.         document.getElementById("function").innerHTML = "Loading";
  35.      }
  36.      else if(xmlObj.readyState==3)
  37.      {
  38.         document.getElementById("citystate").innerHTML = "HEY";
  39.         document.getElementById("progress").innerHTML = "Loading";
  40.         document.getElementById("function").innerHTML = "Loading";
  41.      }
  42. */
  43.   }
  44.  
Please let me know if you need any other piece of code as well.


Cheers
May 7 '08 #3

acoder
Expert Mod 15k+
P: 16,027
I'll also need to see the relevant HTML code. If the code is too much and you have a test site link, post that instead.
May 7 '08 #4

P: 20
Is it possible i can email you my test site?? I dont want it to be public

Thanks again

I'll also need to see the relevant HTML code. If the code is too much and you have a test site link, post that instead.
May 7 '08 #5

acoder
Expert Mod 15k+
P: 16,027
PM me instead.
May 7 '08 #6

acoder
Expert Mod 15k+
P: 16,027
I've had a look, but I am unable to reproduce the problem.

Can you give me some exact steps to trigger the error.
May 7 '08 #7

P: 20
once you click the button 'Create Report' you will be inside the report center. Once you are are inside the report center, click on any link just to navigate away from the page. When you click on the link the the table cells which were saying 'Loading' would disappear and you will see 'undefined' appearing in those cells for a very brief time before you end up in the next page.Please let me know if you were able to reproduce it this time. Thanks for your efforts again.
May 7 '08 #8

P: 20
hey were you able to reproduce error now??
May 8 '08 #9

acoder
Expert Mod 15k+
P: 16,027
Yes, it seems it's only triggered if you leave the page.

I'm not sure what might be triggering it, but perhaps you need to abort the request onunload.
May 8 '08 #10

P: 20
Cool, thanks a lot. I would have a go at it and let you know. Appreciate the time you had spent on this.

Cheers
May 8 '08 #11

Plater
Expert 5K+
P: 7,872
I have noticed on FF a lot when using the FireBug addon that it shows various javascript functions as "undefined" when you attempt to navigate away from a page, that might have pending javascript code running.
May 8 '08 #12

P: 20
I dont think FireBug is the issue in my case, as it shows 'undefined' even in other boxes with no firebug on.
May 8 '08 #13

acoder
Expert Mod 15k+
P: 16,027
Yes, it seems it's only triggered if you leave the page.

I'm not sure what might be triggering it, but perhaps you need to abort the request onunload.
The XMLHttpRequest object has an abort() method which you can use or set the variable to null. Just make sure that the request hasn't already finished. If it has, then there's nothing to worry about anyway.
May 9 '08 #14

Plater
Expert 5K+
P: 7,872
Well I get the undefined error for other functions that have no relation to the xmlhttprequest stuff. They shouldn't even be being accessed, but firebug still likes to throw errors for it.
May 9 '08 #15

P: 20
I tried nulling the xmlhttp object, but still remains the same. I dont really understand how the error gets triggered. Not all the table cells show undefined, only two columns does that. The other column which is also updated with the AJAX response goes blank instead of saying undefined. There are no differences between these columns though. I cant think of a reason why firefox would do it... any suggestions??
May 9 '08 #16

Plater
Expert 5K+
P: 7,872
If you try to call a method/function on an object that doesn't support it, you frequently are returned "undefined"
Like trying to use TOSTRING() vs toString() and such.
May 9 '08 #17

P: 20
Problem sorted,

" xmlObj.readyState == "4" || xmlObj.readyState=="complete" "

This is the line that had the problem. The readyState receives only a numeric response and no string. So this was breaking the script here when i compare readyState to "Complete" and was returning an empty responseText all the time. So when i tried to split responseText and add it to the div elements the first element went null and the others were saying undefined.

Any explanation on why this would break in firefox alone would be appreciated.


Thanks for all your help guys

Cheers
May 12 '08 #18

Plater
Expert 5K+
P: 7,872
IE "doesn't care"?
Also, I notice that in IE, the ready state will be set to a winsock error code number when such events arrive (like host not found), whereas FF throws a javascript exception. So be sure to use try/catch statements.
May 12 '08 #19

acoder
Expert Mod 15k+
P: 16,027
Did you have it as:
xmlObj.readyState == "4" (string) or
xmlObj.readyState == 4 (integer)?
May 12 '08 #20

P: 20
sorry my bad, i have it as an integer not like the previous post.

xmlObj.readyState == 4
(integer).
May 13 '08 #21

acoder
Expert Mod 15k+
P: 16,027
I'm not sure which browsers require "complete", but you should also add in a check for status, i.e.
Expand|Select|Wrap|Line Numbers
  1. if (xmlObj.readyState == 4 || xmlObj.readyState == "complete") {
  2.     if (xmlObj.status == 200) { // OK
  3.         // now it's ready...
May 13 '08 #22

P: 20
exactly now i have added status check and its working fine now.

Thanks for your help, much appreciated.

Cheers
May 13 '08 #23

acoder
Expert Mod 15k+
P: 16,027
You're welcome. Glad it's all working fine now. A simple solution in the end.
May 13 '08 #24

Post your reply

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