Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
            
                    
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        4年前关闭。
                    
                
        

我试图将ajax请求推入deferreds array,但是我不断收到以下错误:

Uncaught SyntaxError: missing ) after argument list

我以这篇文章为例:Pass in an array of Deferreds to $.when()

我是否忽略了一些明显的东西?

<html>
<head>
<script src="https://code.jquery.com/jquery-2.2.2.js"></script>
<script src="../yajf.js"></script>
<script src="../yajf2.js"></script>
</head>
<body>
    <script>
    var deferreds = [];
    $('script[src]').each(function() {
        var src = $(this).attr('src');
        deferreds.push(
            $.get(src,function(data){
                console.log(data);
            }); // error gets thrown on this line
        );
    });
    </script>
</body>
</html>

最佳答案

您已经在;的(单元素)参数列表中添加了deferreds.push()。删除该行上的分号。

    deferreds.push(
        $.get(src,function(data){
            console.log(data);
        }) // remove the semicolon from this line
    );


http://jslint.com

10-08 04:10