javascript - jQuery getScript. How to execute a function after it loads -


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

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

it's supposed run setup method of jsonrpc plugin when loads. receive error:

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

what's problem , how can solve it?

try:

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

you need wrap callbacks function () { }.


Comments