title: Return JSON created in JavaScript HTML Page
body: <p>I've two HTML pages:</p>
  
  <p>1) First HTML Page (page1.html): </p>
  
  <pre><code>&lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          event.preventDefault();
  
          function json1(id,name){
              this.id = id;
              this.name = name;
          }
  
          id_list = Array();
          id_list.push(new json1("1","TEST_1");
          id_list.push(new json1("2","TEST_2");
          id_list.push(new json1("3","TEST_3");
          id_list.push(new json1("4","TEST_4");
          id_list.push(new json1("5","TEST_5");
  
          id_list = JSON.stringify(id_list);
          document.write(id_list);
      });
   &lt;/script&gt;
   &lt;/head&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>2) Second HTML Page (page2.html):</p>
  
  <pre><code>&lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="application/json; charset=utf-8" &gt; 
  &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          event.preventDefault();
  
          $.ajax({
              url : 'http://www.mydomain.com/page1.html',
              type : 'POST',
              async: false,
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function(data){
                  alert("Return OK");
              },
              error: function(xhr, ajaxOptions, thrownError){
                  alert('ERROR = ' + xhr.status + ' - ' + thrownError);
              }       
          });
       });
   &lt;/script&gt;
   &lt;/head&gt;
   &lt;/html&gt;
  </code></pre>
  
  <p>When I execute <a href="http://page2.html" rel="nofollow">http://page2.html</a>, .ajax returns me: 
      ERROR = 200 SyntaxError - Unexpected token &lt;</p>
  
  <p>When I change the dataType: "json" to "text", the .ajax returns me all code HTML of page1.</p>
  
  <p>I need to return the JSON created in page1.html.</p>
  
  <p>Anybody can help me ?</p>
  
  <p>Thanks</p>
  
  <p>ps: sorry about my English.</p>