JQuery getScript How to execute a function after loading

I have this code inside http://www.mysite.local/js/site/functions.js:

$.getScript('/js/common/jquery.jsonrpc.js',
            $.jsonRPC.setup({
                        endPoint: '/api/accounts',
                        namespace: 'mynamespace'
                    })
    );

It is supposed to run setupthe jsonRPC plugin method at boot. But I get an error message:

$.jsonRPC is undefined
http://www.mysite.local/js/site/functions.js

What is the problem and how can I solve it?

0
source share
1 answer

to try:

$.getScript('/js/common/jquery.jsonrpc.js', function() {
         $.jsonRPC.setup({
                        endPoint: '/api/accounts',
                        namespace: 'mynamespace'
                    });
         }
    );

You need to wrap any callbacks with () {}.

+2
source

All Articles