William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

JavaScript: dynamic script calling

JavaScript: dynamic script calling

I need to call an existing javascript with different input parameter in ajax way. The following is my solution:

<script type="text/javascript">
 var t1='variable_from_search_input_field';
 var t2='http://williamjxj.com/exist.js?test_variable=';
 var t3='&tn=news1&from=news2&cl=2&rn=10&ct=0';
 var search_dynamica_variable = t2 + t1 + t3;
 document.write('<script type="text\/javascript" src=');
 document.write(search_dynamica_variable);
 document.write('><\/script>');
</script>

By the way, the following ways not work:


$(window).load(function() {
 $.getScript(search_dynamica_variable);
 $.ajax(search_dynamica_variable);
});

Here is a helpful article in details:

http://unixpapa.com/js/dyna.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: