Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript错误“;“预期功能”;in-if语句_Javascript_Jquery - Fatal编程技术网

JavaScript错误“;“预期功能”;in-if语句

JavaScript错误“;“预期功能”;in-if语句,javascript,jquery,Javascript,Jquery,当我点击页面上的按钮时,我收到一条“预期函数”错误消息。 错误出现在第一条if语句上 我有以下代码: Response_Error: function (xhr, textStatus, errorThrown) { if (textStatus && (textStatus == 'error' || textStatus == 'parsererror')) textStatus = ''; if (errorThrown && errorTh

当我点击页面上的按钮时,我收到一条“预期函数”错误消息。 错误出现在第一条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);
    }
},
Response\u错误:函数(xhr、textStatus、errorshown){
如果(textStatus&&(textStatus='error'| | textStatus=='parsererror'))textStatus='';
如果(ErrorSprown&&ErrorSprown='error')ErrorSprown='';
var html='';
试一试{
html=(textStatus?'textStatus:'+textStatus+'
':'')+ (ErrorSprown?'ErrorSprown:'+ErrorSprown+'
'+'
':'')+ (textStatus | | error抛出?“”:“
”)+xhr.responseText; } 捕捉(错误){ document.write(err.description+'
'+xhr.responseText); } 如果(第页){ 试一试{ if(false){//HACK:将其更改为true,将内容放在文本区域中 html=html.replace(“”,”); html=”“+html+”; } $(Page._lastModalDialog.html(html).fadeIn(“慢”); } 捕捉(错误){ document.write(err.description+'
'+html); } 第页。\u lastmodaldiallog=null; } 否则{ document.write(html); } },
您可以从chrome inspector控制台或fire bug中确定出现错误的行,我认为这与在预期函数时提供变量有关。

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

虽然这可能是一个有用的故障排除建议,但这几乎不是一个答案。这应该是对OP的评论。有时错误是假的。我在VisualStudio2010的IE10中看到了这个“预期函数”错误,没有发现我的代码有任何错误;我在Firefox/Firebug中打开了页面,它运行良好。