Ok I've looked everywhere for this. I'm cutting out a couple of the variable declarations, as I can ensure that my XMLHttpRequest is working.
function submit_edit_form()
{
// id and title are already declared
var x = ajax_edit_form_save(id, 'title', title);
alert(x);
}
function ajax_edit_form_save(id, property, new_value)
{
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
else
{
// screw IE5 & IE6
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.responseText != '')
{
return xmlhttp.responseText;
}
}
// myURL is already defined. I'm not troubleshooting this part, I know it's working
xmlhttp.open("GET", myURL, true);
xmlhttp.send();
}
So when I call submit_edit_form(), which calls ajax_edit_form_save(), I get an alert 'undefined'. I know that the problem is that ajax_edit_form_save() is returning undefined on readyState 1. I'm scratching my head because I only have the return when readyState == 4. How can I hold off on the return value so that x gets the actual responseText?