I have never seen anything like this, and not sure why / what is going on. I am coming from a desktop coding background, it feels like a multi-thread is happening.
The code and output works fine, if I put an alert in, to check my returns, and make sure the data from the PHP code is correct, and that it is returning from the function.
If I let it run at "full speed", no alerts for checking, it is not displaying the data that gets returned, but will show all other HTML being built in the same function.
The code flow is like this, the HTML page builds a basic table, and I am using the document ready to trigger my main java file. Inside the Java code, I am looping through a date range with a "while" (while currentdate <= enddate).
Inside the while loop, I am sending the date to another function, which then, calls the PHP file, to grab data for the date, build the HTML for display, then return that, to the while loop to display on the page.
Here is where it feel like it is creating a second thread. It is like the Java code is not waiting for the data from PHP, and keeps going, since it will output the "day", that is not part of the PHP return.
In the code below, if I were to uncomment any of the alerts, it will show not only the data from PHP, but will display on the page, let it run at full speed, all it get is the HTML that displays the day.
function Get_Events(Year_In, Month_In, Day_In)
{
var EventList = '<table class="InnerTable">\
<thead>\
<tr class="DayNumber">\
<th class="DayNumberCurrent">' + Day_In + '\
</th>\
</tr>\
</thead>';
var EventDateData = {
'Action': 'GetEvents',
'Month': Month_In + 1,
'Day': Day_In,
'Year': Year_In
};
$.ajax({
type: "POST",
url: "Scripts/DataTesting.php",
dataType: "json",
data: EventDateData,
success: function(EventListing) {
//alert(EventListing[0].EventName);
for (var key in EventListing) {
alert('Has Key');
if (EventListing.hasOwnProperty(key)) {
EventList += '<tr>';
EventList += '<td>' + EventListing[key].EventName + '</td>';
EventList += '</tr>';
}
}
},
error: function (jqXHR, error, errorThrown) {
// alert(jqXHR.responseText);
if (jqXHR.status) {
alert(jqXHR.responseText);
} else {
alert("Non-JQ Error: " + error + ", " + errorThrown);
}
}
});
EventList += '</table>';
//alert('HTML: ' + EventList);
return EventList;
}