Q: Dynamically loading js file in ajax I want to include a js file dynamically in ajax when clicked on a button. What I basically want to do is that I want to load a map when clicked on a button. For that i have used two files:
<script type="text/javascript" src="http://maps.google.com/maps?..."></script>
<script type="text/javascript" src="jquery.gmap-1.1.0-min.js"></script>

Now what I want is that when a User clicks on a button then this two files get loaded and the map gets displayed without page getting refresh.
Also when a user has clicked on the button and this two script has been loaded then clicking it second time doesnt make the script load again.
Any help in this matter will be highly appreciated.

Thnx for your response. Anyways i tried to do it using $script and 
RequireJs but the map was unable to load.
Here is my code that I had wriiten:
<script type="text/javascript" src="../js/jquery-1.7.js"></script>
<script src="../js/script.js"></script>
<script>
function googlemaps()
{
  $script('"http://maps.google.com/maps?file=api&..', 'maps', function() 
  {
      $script('../js/jquery.gmap-1.1.0-min.js', 'jquery', function() {
      $("#map").gMap({address: "USA", markers: [{address: "USA"}]});
      });
  });
}
</script>

<input name="Butoon" type="button" value="Button" onclick="javascript: googlemaps();" />

<div id="map"></div>

The error that I got was: "G_NORMAL_MAP is not defined" and 
"GMap2 is not defined"(the error is coming because 
jquery.gmap-1.1.0-min.js is loaded before 
http://maps.google.com/maps?file=api&.. loads ). The same error is 
being repeated while using RequireJs. Can you please say where I am 
making the mistake.
Thanks in advance.

A: you should take a look at some script/module loaders instead, like $cript and RequireJS. basically, they do the same thing, and more.
