'SyntaxError: expected expression, got <' from $.getScript

814 views Asked by At

I want to create a jQuery multilingual plugin. I also want to open the language files containing the "object" inside my plugin function and access its content.

$.getScript('lang/' + settings.language + '.js').done(function() {
  console.log('loaded this');
}).fail(function() {
  consoleError('language file does not exist!');
});

The above code gives me the following error.

SyntaxError: expected expression, got '<'

Can you make a suggestion?

1

There are 1 answers

0
JavaSheriff On

My assumption is that you are referencing the script incorrectly and the web server is serving a 404 html page.
Change your code like that:

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