How would I pass data to an external script loaded with $.getScript()?

So I’m trying to load a javascript remotely using jquery’s $ .getScript, but I’m puzzled on how I can pass data to the external script.

I’ve tried setting variables before the call but they aren’t available in the script that gets loaded, and when I try to send/retrieve them using the query string, the remote script tries to read the querystring of the base file that it gets called from, not itself. Is there any other way to do this? Or is it possible to have a javascript file read its own querystring rather than the file it’s called from (that’s loaded in the browser)?

// editor ini
var editor_ini = { page: current_page, action: 'edit' };
var foo = 'bar';
// load the editor
$  .getScript('assets/desktop/desklets/'+launcher.config.editor+'/execute.js', function(){});

In the execute.js file, the editor_ini and foo are both unavailable, I get the same result with:

// load the editor
$  .getScript('assets/desktop/desklets/'+launcher.config.editor+'/execute.js', { page: current_page, action: 'edit', foo: 'bar' }, function(){});

because the remote script seems to be getting the query string from the original document rather than the one used when calling the file.

If it matters, I was trying to use the query object plugin for jquery for reading the query string.

newest questions tagged jquery – Stack Overflow

About Admin