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

Ajax and FireFox problem

Claus Mygind
100+
P: 571
I have a problem with some ajax communications on some users' computers.

Sometimes data sent via ajax would not post to the database. I resolved the problem by deleting the user's profile and creating a new profile.

My dilemma is this, I don't know what part of the profile was creating the problem, so I don't know if it will reappear?

Here is what I do know (see my code below).

1. The query was always present in the query string being sent
2. The web server (Apache 2.2.10) shows a 200 code in the access log even though no post occurred on the database (MySQL 5.0 MyISAM storage engine).
3. If I set a breakpoint with firebug on line 51 (the test for the readyState) I could get it to post properly.

So it appears as if the script is running a little ahead thereby creating an incomplete query. And it is probably returning the 200 code because there is nothing on the server side app to trap and error if nothing occurs. That however is besides the point, the problem is the client side script in conjunction with the user's profile.

I know you can programatically control the user's firefox profile, but I am not sure which part I need to check or even how to check it?


Expand|Select|Wrap|Line Numbers
  1. var timeHttp;
  2.  
  3. function submitTime()
  4. {
  5.     if (window.ActiveXObject) 
  6.     {
  7.         timeHttp = new ActiveXObject("Microsoft.XMLHTTP");
  8.     }else if (window.XMLHttpRequest) {
  9.         timeHttp = new XMLHttpRequest();
  10.     }
  11.     var url = "/<myPath>/<myApp>?timeStamp=" + new Date().getTime();
  12.     var queryString = buildTime();
  13.     timeHttp.onreadystatechange = handleTimeStateChange;
  14.     timeHttp.open("POST", url, true);
  15.     timeHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  16. //---------------------------------
  17. When stopped here
  18. query was always present
  19. //---------------------------------
  20.     timeHttp.send(queryString);
  21. }
  22. function buildTime()
  23. {
  24.     qString = "Action="+document.getElementById("MySubmit").value; 
  25.  
  26.     for (var i = 0; i < aDailyTime.length; i++ )
  27.     {
  28.         qString += "&RECKEY"+i+"="+aDailyTime[i].RECKEY;
  29.         qString += "&EMPNO"+i+"='"+aDailyTime[i].EMPNO+"'";
  30.         qString += "&WORKDAY"+i+"="+aDailyTime[i].WORKDAY;
  31.         qString += "&PRJCTNAME"+i+"='"+encodeURIComponent(aDailyTime[i].PRJCTNAME)+"'";
  32.         cTotTime = parseFloat(aDailyTime[i].HOURS)+parseFloat(aDailyTime[i].minutes);
  33.         qString += "&STARTMILES"+i+"=";
  34.         qString += ( aDailyTime[i].STARTMILES == "" ) ? 0 : aDailyTime[i].STARTMILES;
  35.         qString += "&ENDMILES"+i+"=";
  36.         qString += ( aDailyTime[i].ENDMILES == "" ) ? 0 : aDailyTime[i].ENDMILES;
  37.         //if "--->" is found in project name then this employee's departmetn is not assigned to this job's department
  38.         cIsDept  = ( aDailyTime[i].PRJCTNAME.substring(0,4) == "--->" ) ? 'F' : 'T';
  39.         qString += "&isDept"+i+"='"+ cIsDept +"'";
  40.     }
  41.     qString += "&method=POST";
  42.     return qString;
  43. }
  44.  
  45. function handleTimeStateChange() 
  46. {
  47. //----------------------------------------
  48. This is where the problem would
  49. occur.  Not sure why?
  50. //---------------------------------------
  51.     if (timeHttp.readyState == 4) 
  52.     {
  53.         if (timeHttp.status == 200) 
  54.         {
  55.             parseTimeResults();
  56.         }
  57.     }
  58. }
  59.  
  60. function parseTimeResults() {
  61.  
  62.     var returnedString = timeHttp.responseText;
  63.     var aReturn = new Array();
  64.     aReturn = returnedString.split(';');
  65.     if ( aReturn[0] == "An error occured") 
  66.     { 
  67.         eAlert  = aReturn[0]+"\n"
  68.  
  69.         if ( aReturn[1] == "Error on time submittal") { 
  70.             eAlert += aReturn[1]+" "+document.getElementById("EMPNO").value
  71.         }else{ 
  72.             eAlert += aReturn[1]+"\n"
  73.             eAlert += aReturn[2]+"\n"
  74.             eAlert += aReturn[3]+"\n"
  75.             eAlert += aReturn[4]
  76.         }
  77.  
  78.         alert( eAlert );
  79.  
  80.     }else{ 
  81.         alert( aReturn[0] );
  82.     }
  83. }
  84.  
  85.  
Apr 17 '09 #1
Share this Question
Share on Google+
4 Replies


acoder
Expert Mod 15k+
P: 16,027
Since you deleted and created a new profile, has the problem ever occurred again?
Apr 21 '09 #2

Claus Mygind
100+
P: 571
@acoder
Yes the problem did re-occur. But just now I have been able to solve the problem. As usual it was within my own code although I still do not understand what or why it did what it did.

I was combining some of my pre-ajax code with my current ajax code when submitting a record.

My action property for the form was set at action = "return false;" to prevent the enter button from submitting the form. This is standard in all my apps as I do some validation on the form before submitting. But in using the ajax approach to send only the data and not the form to the web server, the faulty code crossed the function with the "form.submit();" line which it should not have. There was no specific action or url for the form.submit() to execute but it seemed to mess up the "readyState" on the ajax where it seems nothing was submitted at all. I can accept and understand all that. But what baffles me is the access log on the web server shows that the receiving program was called and executed with a return code of 200. Well I have eliminated the cross link and the problem has been solved.

Thank you for checking in on me
Apr 24 '09 #3

acoder
Expert Mod 15k+
P: 16,027
@Claus Mygind
Not sure exactly what the problem might have been, but I can say that there's no need for this as long as you call your validation function onsubmit:
Expand|Select|Wrap|Line Numbers
  1. <form ... onsubmit="return validate();">
If you return false when validation fails, then the form would not be submitted, thus you can set a correct action and don't need to call the submit() method.
Apr 24 '09 #4

Claus Mygind
100+
P: 571
Thanks for your help.
Apr 27 '09 #5

Post your reply

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