AJAX async true在IE 11中返回undefined或null引用错误

时间:2016-09-13 02:58:12

标签: javascript jquery ajax undefined internet-explorer-11

在async设置为true的情况下使用此AJAX调用会导致以下函数(请参见下文)失败,并显示未定义的错误。显然,这是因为在浏览器尝试使用它之前,AJAX调用没有获得返回值。如果async设置为false,则此AJAX函数可以正常工作。我错过了什么?

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);

}

此AJAX调用将失败:无法获取未定义或空引用的属性长度。此调用将使用异步设置为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++)

0 个答案:

没有答案