Question

I'm getting the error: "ErrorType: SyntaxError, Message: Unexpected identifier ,FuncName: Request UserCallback" in the JS console. I looked for an answer here and found a question where the person just had sloppy syntax. I put my code through JSLint to see if I had the same problem, turns out I didn't.

This code is running in the extension scope:

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

The report doesn't give a line number in my code, but I believe the assignment it's referring to is after console.log("Collections JSON fetched successfully!"); because that fires. I'm at a loss.

Was it helpful?

Solution

In testing your code, I determined that the problem lies with your collections.html micro-template syntax. Please note that micro-template syntax rules are strict, in particular when using variables which must follow the following syntax rules:

  • Variable usage syntax requires an equal (=) sign
  • There must not be any spaces in the syntax when using variables

Hence, for variables use

<%=varName%>
and not
<% varName %>

[Disclosure: I am a Crossrider employee and have been in contact with @ViciousAmbitious via our support channel]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top