title: Update src of script tag using jQuery - reload a script with jQuery without refreshing page
body: <p>The question says it all. How to update the "src" of script tag using jQuery.
  Let say, I have a script, </p>
  
  <pre><code> &lt;script id="somescript" type="text/javascript" src=""&gt;&lt;/script&gt;
  </code></pre>
  
  <p>So when I a click on a button, the src of the script must be added. Like,</p>
  
  <pre><code> &lt;script id="somescript" type="text/javascript" src="linktoscript.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>I am doing it with a click handler like this, using the following code.</p>
  
  <pre><code>$("#somescript").attr("src","linktoscript.js");
  </code></pre>
  
  <p>It actually updates the src but when I check it via firebug, it tells me to refresh the page to get the script working.</p>
  
  <p><strong>Research:</strong></p>
  
  <p>After some research, I've found $.get() of jQuery would do the job and yes, it loads the script. But it is not getting my job done.</p>
  
  <p><strong>The Actual Problem:</strong></p>
  
  <p>I am trying to load Google's conversion code using Ajax on successful form submission.</p>
  
  <p>Here is the part of the Ajax script that should work for the Google's conversion code.</p>
  
  <pre><code>                    if (res == "yes") {
                          $('#success').fadeIn().delay(5000).fadeOut();
                          $('#regform')[0].reset();
                          window.location.href = '#'; 
                          /* &lt;![CDATA[ */
                          var google_conversion_id = xxxxxxxxx;
                          var google_conversion_language = "en";
                          var google_conversion_format = "2";
                          var google_conversion_color = "ffffff";
                          var google_conversion_label = "CiaXCOXjzlcQy__EyQM";
                          var google_remarketing_only = false;
                          /* ]]&gt; */
  
   $.getScript("http://www.googleadservices.com/pagead/conversion.js");   
    }
  </code></pre>
  
  <p>It loads the conversion script but when I check it from firebug, all the values of the conversion variables are null.
  So I am giving it a try by putting all of the conversion code into the html file and then load the conversion script like,</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
    /* &lt;![CDATA[ */
    var google_conversion_id = xxxxxxxxx;
    var google_conversion_language = "en";
    var google_conversion_format = "2";
    var google_conversion_color = "ffffff";
    var google_conversion_label = "CiaXCOXjzlcQy__EyQM";
    var google_remarketing_only = false;
    /* ]]&gt; */ 
   &lt;/script&gt;
  
   &lt;script type="text/javascript" src="#"&gt;&lt;/script&gt; &lt;!--Update this src--&gt;
  
   &lt;noscript&gt;
    &lt;div style="display:inline"&gt;
     &lt;img height="1" width="1" style="border-style:none;" alt="" src="#" /&gt;
    &lt;/div&gt;
   &lt;/noscript&gt;
  </code></pre>
  
  <p>Any Help?</p>
  
  <p><strong>Link:</strong></p>
  
  <p>Here is the link to the live site : <a href="http://goo.gl/ZigoqL" rel="noreferrer">Link</a></p>
  
  <p><strong>Update:</strong>
  This is what I get. In the firebug's script panel, after form submission,
  <img src="https://i.stack.imgur.com/PLRL6.png" alt="enter image description here"></p>