title: Get a JSON array with HTTP Get using javascript (jquery)
body: <p><em>I've been trying some code from here to achieve my goal but I haven't found the solution yet.</em></p>
  
  <p><strong>Goal</strong>: I have to get a JSON objects array from a web (through the URL) using GET method. I have to do that in Javascript or HTML. I have been trying in javascript with jquery and with ajax. The idea is when the webpage I'm making loads I have to get the JSON objects array. I would want to save the JSON objets array fetched in a string to manipulate it.</p>
  
  <p>Example of JSON array that I have to get from <a href="http://www.example.com/example" rel="nofollow">http://www.example.com/example</a></p>
  
  <pre><code>[
      {
          "type": "1",
          "id": "50a92047a88d8",
          "title": "Real Madrid"
      },
      {
          "type": "1",
          "id": "500cbb1a5ef23",
          "title": "Fernando Alonso"
      }
  ]
  </code></pre>
  
  <p>When I run my code in the browser I always get no response.</p>
  
  <p>These are some pieces of code I've tried:</p>
  
  <p>HTML Code</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;script src="http://code.jquery.com/jquery-1.10.2.min.js"&gt;&lt;/script&gt;
      &lt;script src="http://code.jquery.com/ui/1.8.23/jquery-ui.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="script.js"&gt;&lt;/script&gt;
      &lt;link type = "text/css" rel = "stylesheet" href = "stylesheet.css"/&gt;
  &lt;/head&gt;
  &lt;body onload = "httpGet('http://www.example.com/example')"&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Javascript code</p>
  
  <pre><code>function httpGet(theUrl)
  {
  $.getJSON(theUrl, function(data)
  {
      $.each(data, function()
      {
          console.log(this['title']);
      })
  });
  }
  </code></pre>
  
  <p>Other Javascript code</p>
  
  <pre><code>$.ajax(
  {
      url: theUrl,
      type: 'GET',
      dataType: 'json',
      accept: 'application/json',
      success: function(data)
      {  
          console.log(data);
          var objets= $.parseJSON(data);
  
          $.each(objets, function(i, obj)
          {
             console.log(obj.title);
          });
      }
  });
  </code></pre>
  
  <p>And I have prove a lot of code from here (stak overflow)...</p>
  
  <p>Thank you very much and excuse me for my English.</p>
  
  <p>Edit:</p>
  
  <p>Some time ago I tried with stringify, but I don't really known how can it works.
  I proved the following:</p>
  
  <pre><code>function httpGet(theUrl)
  {
      var xmlHttp = null;
      xmlHttp = new XMLHttpRequest();
      xmlHttp.open("GET", theUrl, true ); // I tried with true and with false
      xmlHttp.send();
      var answer= xmlHttp.responseText;
      var str = JSON.stringify(answer);
      console.log(str);
      var jsonResponse = JSON.parse(str);
      console.log(jsonResponse);
  }
  </code></pre>