title: In javascript: Changing "src" for a newly created script-element doesn't work..?
body: <p>I'm <em>very</em> new to javascript, but I've managed to stitch the following together from different code-snippets, and forum-posts:</p>
  
  <pre><code>var s = document.createElement("script");
  s.src = "http://service.somewebsite.com/?api-key=4P1k3y5R4w50m3";
  document.getElementsByTagName("body")[0].appendChild(s);
  </code></pre>
  
  <p>However - it doesn't work.</p>
  
  <p>The source-attribute is obviously not real (the service asked me to not share the API-key), but pasting the actual one into a browser, I get the excact script I want - with the right callback and everything.</p>
  
  <p>I find it odd that this code doesn't work since the very similar</p>
  
  <pre><code>var i = document.createElement("img");
  i.src = "http://i.imgur.com/TsCGbsy.jpg";
  document.getElementsByTagName("body")[0].appendChild(i);
  </code></pre>
  
  <p>...executes just fine, when it takes its place. Is there something I don't know about changing the source of a script-element, or is there something else I've overlooked?</p>
  
  <p>On a side note: I want to end up having "s.src" rely on some variables like the method, the api-key etc. (which is why I define it like this). If anyone has some other elegant solution  to this, I'd be thankful as well. Any tips on syntax etc. are also very welcome.</p>
  
  <p>Thanks in advance for any sort of help on this!</p>
  
  <p>EDIT: I maybe should have mentioned that I'm trying to execute code from a source that consists of a JSON-object wrapped in a callback-function. The link itself works fine, and the function is executed properly when using</p>
  
  <pre><code>&lt;script src = "http://service.somewebsite.com/?api-key=
  k3y&amp;callback=myFunction"&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>I'm basically attempting to do the same thing, only with (src) being stitched together from a string and one or more variables.</p>