QUOTE(moopet @ 28 Jun, 2009 - 09:54 AM)

Can we see where the callback to getCalendarMonth() is defined?
I don't mind showing it but it's not really necessary. Although I did misspeak when talking about the sequence of events so maybe this will clarify things. Ok, processForm() get called in the javascript when you submit the form. This function queries the server for processForm.php which contains the doe you saw. That code executes if there are no errors. There's a call back function in my Javascript, processEvent().
This parses the server response as javascript. I know it works because the alert in the server code as well as my getEvents() function returns the correct response. Notice though that there is also a call to getCalendarEvents() in my server code. Also, notice that in the getCalendarEvents() function contains an alert(). Somehow, between the alert call from the server, and the alert in the getCalendarEvents function the variable changes.
So here it is:
This calls the PHP code you saw.
CODE
function processForm()
{
if(http.readyState == 4)
{
params = '?date=' + document.getElementById('form_date').value;
params += '&name=' + document.getElementById('name').value;
params += '&phone=' + document.getElementById('phone').value;
params += '&email=' + document.getElementById('email').value;
params += '&starthour=' + document.getElementById('starthour').value;
params += '&startminute=' + document.getElementById('startminute').value;
params += '&endhour=' + document.getElementById('endhour').value;
params += '&endminute=' + document.getElementById('endminute').value;
params += '&description=' + document.getElementById('description').value;
params += '&rand=' + parseInt(Math.random() * 999999999);
http.open('get', 'processeventform.php' + params, true);
http.onreadystatechange = processEvent;
http.send(null);
}
else
{
document.getElementById('event_errors').innerHTML = "<p>Processing Form</p>";
setTimeout('processForm()', 30);
}
}
This retrieves the repsonse and parses it as java script:
CODE
function processEvent()
{
if(http.readyState == 4)
{
if(http.status == 200)
{
document.getElementById('event_errors').innerHTML = eval(http.responseText);
}
}
else
{
document.getElementById('event_errors').innerHTML = "<p>Processing Form</p>";
}
}
Note that it receives this response, which contains a call to getCalendarMonth(). Keep in mind that the alert here shows the correct response and that getEvents() works correctly.
CODE
echo "alert(\"" . $date . "\");";
echo "getEvents(\"" . $date . "\");";
echo "getCalendarMonth(\"" . $date . "\");";
However, for some reason when it gets to this point, the alert shows the wrong thing and the function does not respond correctly.
CODE
function getCalendarMonth(date)
{
if(http.readyState ==4)
{
alert(date);
if(date != null)
{
var url = 'view_cal.php?date=' + date;
url += '&rand=' + parseInt(Math.random() * 999999999);
http.open('get', url, true);
}
else
{
var url = 'view_cal.php';
url += '?rand=' + parseInt(Math.random() * 999999999);
http.open('get', url, true);
}
http.onreadystatechange = show_cal;
http.send(null);
}
else
{
document.getElementById('calendar').innerHTML = "<table><tr><td>Getting Calendar</td></tr></table>";
setTimeout('getCalendarMonth(' + date + ')', 30);
}
}
That should covers any requests. There are no global variables besides http and I set a random parameter when request things from the server so cache should not be an issue. Keep in mind my question is, why would the two alerts show something different even though they are virtually called back to back.