繁体   English   中英

if语句中的JavaScript错误“函数预期”

[英]JavaScript error “Function expected” in if statement

当我单击页面上的按钮时,我收到“功能预期”错误消息。 错误发生在第一个if语句中。

我有以下代码:

Response_Error: function (xhr, textStatus, errorThrown) {
    if (textStatus && (textStatus == 'error' || textStatus == 'parsererror')) textStatus = '';
    if (errorThrown && errorThrown == 'error') errorThrown = '';
    var html = '';
    try {
        html = (textStatus ? 'textStatus: ' + textStatus + '<br/>' : '') +
            (errorThrown ? 'errorThrown: ' + errorThrown + '<br/>' + '<br/>' : '') +
            (textStatus || errorThrown ? '' : '<hr/>') + xhr.responseText;
    }
    catch (err) {
        document.write(err.description + '<br/>' + xhr.responseText);
    }

    if (Page._lastModalDialog) {
        try {
            if (false) { // HACK: change this to true to put contents on a textarea
                html = html.replace('<', '&lt;').replace('>', '&gt;');
                html = "<form><textarea rows='40' cols='120'>" + html + "</textarea></form>";
            }
            $(Page._lastModalDialog).html(html).fadeIn("slow");
        }
        catch (err) {
            document.write(err.description + '<br/>' + html);
        }
        Page._lastModalDialog = null;
    }
    else {
        document.write(html);
    }
},

您可以从chrome检查器控制台或fire bug中确定出现错误的行,我认为这与在预期函数时提供变量有关。

这通常是预期回调函数的情况。 检查代码并查看是否存在其中一个参数应该是回调函数的位置。 您还可以执行console.log xhr.onreadystatechange,以查看是否有分配给xhr对象的回调。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM