1

In my .php page at bottom

(function ($) {
    $(document).ready(function () {
        var Atest = 'Hi';

        $.getScript(app_consts.VIEW_JS + 'something.js');
    });
})(jQuery);

In the something.js file I have writen

(function ($) {
    $(document).ready(function () {
        console.log(Atest);
    });
})(jQuery);

And in the console value is not printed. I don't know how to get that.

Rana Ghosh
  • 4,344
  • 5
  • 21
  • 38

1 Answers1

2

Change scope of variable like..

<script type="text/javascript">
    var Atest = 'Hi';

    (function ($) {
    $(document).ready(function () {
        //var Atest = 'Hi';

        $.getScript(app_consts.VIEW_JS + 'something.js');
    });
    })(jQuery);
</script>

you can read more about Javascript Scope from here.

vijay
  • 711
  • 5
  • 15