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?
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?
Code:
var timeHttp; function submitTime() { if (window.ActiveXObject) { timeHttp = new ActiveXObject("Microsoft.XMLHTTP"); }else if (window.XMLHttpRequest) { timeHttp = new XMLHttpRequest(); } var url = "/<myPath>/<myApp>?timeStamp=" + new Date().getTime(); var queryString = buildTime(); timeHttp.onreadystatechange = handleTimeStateChange; timeHttp.open("POST", url, true); timeHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); //--------------------------------- When stopped here query was always present //--------------------------------- timeHttp.send(queryString); } function buildTime() { qString = "Action="+document.getElementById("MySubmit").value; for (var i = 0; i < aDailyTime.length; i++ ) { qString += "&RECKEY"+i+"="+aDailyTime[i].RECKEY; qString += "&EMPNO"+i+"='"+aDailyTime[i].EMPNO+"'"; qString += "&WORKDAY"+i+"="+aDailyTime[i].WORKDAY; qString += "&PRJCTNAME"+i+"='"+encodeURIComponent(aDailyTime[i].PRJCTNAME)+"'"; cTotTime = parseFloat(aDailyTime[i].HOURS)+parseFloat(aDailyTime[i].minutes); qString += "&STARTMILES"+i+"="; qString += ( aDailyTime[i].STARTMILES == "" ) ? 0 : aDailyTime[i].STARTMILES; qString += "&ENDMILES"+i+"="; qString += ( aDailyTime[i].ENDMILES == "" ) ? 0 : aDailyTime[i].ENDMILES; //if "--->" is found in project name then this employee's departmetn is not assigned to this job's department cIsDept = ( aDailyTime[i].PRJCTNAME.substring(0,4) == "--->" ) ? 'F' : 'T'; qString += "&isDept"+i+"='"+ cIsDept +"'"; } qString += "&method=POST"; return qString; } function handleTimeStateChange() { //---------------------------------------- This is where the problem would occur. Not sure why? //--------------------------------------- if (timeHttp.readyState == 4) { if (timeHttp.status == 200) { parseTimeResults(); } } } function parseTimeResults() { var returnedString = timeHttp.responseText; var aReturn = new Array(); aReturn = returnedString.split(';'); if ( aReturn[0] == "An error occured") { eAlert = aReturn[0]+"\n" if ( aReturn[1] == "Error on time submittal") { eAlert += aReturn[1]+" "+document.getElementById("EMPNO").value }else{ eAlert += aReturn[1]+"\n" eAlert += aReturn[2]+"\n" eAlert += aReturn[3]+"\n" eAlert += aReturn[4] } alert( eAlert ); }else{ alert( aReturn[0] ); } }
Comment