Crossrider意外的标识符,但JSLint通过

时间:2014-02-20 16:06:01

标签: google-chrome-extension crossrider

我在JS控制台中收到错误:“ErrorType:SyntaxError,Message:Unexpected identifier,FuncName:Request UserCallback”。我在这里找到了一个答案,并找到了一个问题,这个人只是语法松散。我把我的代码通过JSLint来查看我是否有同样的问题,结果我没有。

此代码在扩展范围内运行:

function loadTool()
{
    $('body').prepend(appAPI.resources.get('html/base.html'));
    appAPI.resources.includeCSS('css/mycss.css');
    $('#tool-logo').attr('src', appAPI.resources.get('img/logo-white.png'));
    $('#tool-nav-btn').attr('src', appAPI.resources.get('img/btn-menu.png'));

    appAPI.request.get({
        url: 'https://url',
        onSuccess: function(response) {             
            var json = appAPI.JSON.parse(response);

            if (json.messages)
            {
                console.log("User is logged in.");
                return getColl();
            }

            return $('#tool-content').html(appAPI.resources.get('html/login.html'));
        },
        onFailure: function(httpCode) {
            return console.log("Failure. HTTP Code: " + httpCode);
        }
    });
}

function getColl()
{
    appAPI.request.get({
        url: 'https://url',
        onSuccess: function(response) {
            console.log("Collections JSON fetched successfully!");

            var jsonColl = appAPI.JSON.parse(response);

            return $('#tool-body').html(appAPI.resources.parseTemplate('html/collections.html', {collections: jsonColl}));
        },
        onFailure: function(httpCode) {
            return console.log("Failed to GET Collections: " + httpCode);
        }
    });
}

报告中没有给出我的代码中的行号,但我相信它所引用的赋值是在console.log之后(“Collections JSON成功获取!”);因为那火了。我很茫然。

1 个答案:

答案 0 :(得分:1)

在测试代码时,我确定问题在于您的collections.html micro-template语法。 请注意,微模板语法规则是严格的,特别是在使用必须遵循以下语法规则的变量时:

  • 变量用法语法需要等号(=)
  • 使用变量时,语法中不能有任何空格

因此,对于变量使用

<%=varName%>
而不是
<% varName %>

[披露:我是Crossrider员工,并通过我们的支持渠道与@ViciousAmbitious联系]