[jQuery] Re: $.getScript() - how to load into JSON formatted object?

2008-07-16 Thread jquertil

they thanks for the reply. I don't fully understand what the
parameters in this line do exactly. why is variable in 'quotation'
marks?

fn = new Function( 'variable', code );

thanks!


On Jul 8, 4:03 pm, Michael Geary [EMAIL PROTECTED] wrote:
 OK, try this. It's the same idea as the code I posted before:

 var blah = {
 dynaLoad : function( variable ) {
 $.get( 'alert.js', function( code ) {
 var fn = new Function( 'variable', code );
 fn( variable );
 });
 },
 somethingElse : ''
 };

 blah.dynaLoad('cool beans');

 -Mike

  -Original Message-
  From: jquery-en@googlegroups.com
  [mailto:[EMAIL PROTECTED] On Behalf Ofjquertil
  Sent: Tuesday, July 08, 2008 1:37 AM
  To: jQuery (English)
  Subject: [jQuery] Re: $.getScript() - how to load into JSON
  formatted object?

  thanks for the answer Mike. I probably wasn't very clear.

  I'm trying to make the loading happen as part of
  blah.something(variable).

  something kinda like this:

  var blah ={
 dynaLoad : function(variable){
$.getScript('alert.js',variable) // the script would
  simply contain the line alert(variable);
 },
 somethingElse : ''
  }

  blah.dynaLoad('cool beans'); // this would now produce a cool beans
  alertbox.


[jQuery] Re: $.getScript() - how to load into JSON formatted object?

2008-07-08 Thread jquertil

thanks for the answer Mike. I probably wasn't very clear.

I'm trying to make the loading happen as part of
blah.something(variable).

something kinda like this:

var blah ={
   dynaLoad : function(variable){
  $.getScript('alert.js',variable) // the script would simply
contain the line alert(variable);
   },
   somethingElse : ''
}

blah.dynaLoad('cool beans'); // this would now produce a cool beans
alertbox.


[jQuery] Re: $.getScript() - how to load into JSON formatted object?

2008-07-06 Thread Michael Geary

This is all from the same domain, so you don't have cross-domain issues,
right?

I just tried this code, and it works nicely:

$.get( 'alert.js', function( code ) {
var blah = {
something : new Function( 'variable', code ),
something_else : 'hello'
};

blah.something('whatsup'); // 'whatsup'
});

alert.js contains the one line:

alert(variable);

BTW, in case it's of interest, the file extension doesn't have to be .js for
this code to work, since it's just loading it as a text file.

-Mike

 From: jquertil
 
 var blah = {
something : function(variable){
   alert(variable);
},
something_else : 'hello'
 }
 
 alert( blah.something_else() ); // 'hello'
 blah.something('whatsup'); // 'whatsup'
 
 so far nothing unusual... but... how can I put the blah.something
 function into a separate .js file and load it?
 Played around with $.getScript() but nothing works :( 
 Ideally, my file alert.js would contain only the line with 
 alert(variable); in it. Can that be done?