Pero
Pero

Reputation: 794

How to pass data to js-file via $getScript and how to access this data in this called js-file?

How can I pass a variable via $getScript() to the called js-file here bfile.js.

var x = new Array();
$.getScript('bfile.js', x);

I called it normally because I read that in the new called javascript file all variables are visible but for the variable x, I get a Uncaught ReferenceError: x is not defined. Please help!

Upvotes: 0

Views: 897

Answers (1)

Chamika Sandamal
Chamika Sandamal

Reputation: 24302

you don't need to pass variables. just declare the variable as global variable before load the script. then it will available for any script load after that.

Upvotes: 1

Related Questions