3

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?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
ali tajari
  • 25
  • 3
  • 1
    That error normally indicates that you're loading HTML in the `getScript()` call - usually due to an error page being returned instead of the expected script. Check the actual response in the console – Rory McCrossan Sep 18 '18 at 14:41
  • does your .js file contain a ` – ADyson Sep 18 '18 at 14:47

1 Answers1

0

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');
                    }
                });
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159