Using this AJAX call with async set to true causes the following function (see below) to fail with undefined error. Clearly it is because the AJAX call is not getting a return value before the browser attempts to use it. If async is set to false this AJAX function works. What am I missing?
function AjaxCmd(cmd) {
var txtRetval;
//alert(cmd);
$.ajax({
type: "POST",
url: "/telligent/rpjquery-functions.asp",
data: "cmd=" + cmd,
datatype: "html",
//async Not supported in IE8 or IE9 11082014
cache: false,
async: true,
success: function(data) {
//alert("success");
txtRetval = data;
},
error: function (request, status, error) {
//alert(request.responseText);
txtRetval = false;
},
failure: function() {
//alert("failure");
txtRetval = false;
}
});
//return callback( txtRetval );
if (txtRetval == "not authenticated") {
jQT.goBack("#");
location.reload(true);
alert(txtRetval);
return (false);
} else {
//
}
return (txtRetval);
}
This AJAX call will fail with: unable to get property length of undefined or null reference. This call will work with async set to false:
var filterstring = AjaxCmd("getfilterstring&intFormID="+intFormID+"&SF="+SF+"&txtFormType="+txtFormType+"&a="+a+"&s="+s);
var filterstringlength = filterstring.length
for (var x = 1; x <= filterstringlength; x++)