我在 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 fetched succeeded!"); 因为那会着火。我不知所措。