title: How to execute javascript returned from PageMethod
body: <p>I have page, where I'm making an ajax call to <code>PageMethod</code>, and as a result I'm getting some html string, which I need to append to some div. Now Html string has some javascript code in it, so I expect this js code to execute, after I append html to div. But the problem is, I'm getting error saying that - <code>Microsoft JScript runtime error: Access is denied.</code>, this error gets thrown when globalEval method tries to execute.</p>
  
  <p>This is an ajax call I make</p>
  
  <pre><code>var data ={id: id};
  
  $.ajax({
  
      type: "POST",
      url: "/srv/Loader.aspx/LoadUserControl",
      contentType: "application/json; charset=utf-8",
      data: JSON.stringify(data),
      dataType: "json",
      success: function (data) {
         $('#TargetDivID').html(data.d);
      },
      error: function (error) {
         $('#TargetDivID')..html("Control can not be loaded");
         console.log("LOG: Exeption trying to load Control:\n" + error.responseText);
      }
  });
  </code></pre>
  
  <p>Here is the Html returned by WebMethod:</p>
  
  <pre><code>&lt;div class="someclass" id="inHouseAdModule" style="display:none;"&gt;
  Some Html Content
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              Some logic goes here
          });
      &lt;/script&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Any ideas how can I fix this ?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code> &lt;div class="someclass" id="inHouseAdModule" style="display:none;"&gt;
      Some Html Content
          &lt;script type="text/javascript"&gt;            
                  Some logic goes here            
          &lt;/script&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p><strong>Does not work as well.</strong></p>
  
  <p><strong>EDIT:</strong>
  I've added debugger at the beginning of JS code, but exception was thrown before reaching that point.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt; 
     debugger;           
     Some logic goes here            
  &lt;/script&gt;
  </code></pre>