The problem with the code was two incorrect variables in the onreadystatechange function:
1. I did not capitalize the "S" in .readyState
2. I left out "Obj" to XMLHttpRequest - the Http request object.
Code:
XMLHttpRequestObj.onreadystatechange = function(){
if (XMLHttpRequestObj.readyState == 4 && XMLHttpRequestObj.status == 200){
callback(XMLHttpRequestObj.responseText);
}
}
I do have 2 follow-up questions however, if anyone has the answer to them, please let me know. Thanks.
1. The alert message that I've setup only occurs every other entry, i.e. the first time I fill and submit the form, the alert occurs; second time through, alert doesn't occur; third time, the alert occurs. Why is that?
2. Once the first form is successfully inserted into the database, I'd like to display another form. How can I confirm a successful insert and only then display another, new form?