我想创建一个 jQuery 多语言插件。我还想打开插件函数中包含“对象”的语言文件并访问其内容。
$.getScript('lang/' + settings.language + '.js').done(function() {
console.log('loaded this');
}).fail(function() {
consoleError('language file does not exist!');
});
上面的代码给了我以下错误。
SyntaxError: expected expression, got '<'
你能提个建议吗?
最佳答案
我的假设是您错误地引用了脚本,并且 Web 服务器正在提供 404 html 页面。
像这样更改您的代码:
jQuery.ajax({
type: "GET",
url: 'lang/' + settings.language + '.js',
dataType: "script",
error: function (XMLHttpRequest, textStatus, errorThrown) {
consoleError('language file does not exist!');
},
success:function(){
console.log('loaded this');
}
});
关于jquery - 'SyntaxError : expected expression, 从 $.getScript 得到 <',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52389092/