title: Populate HTML with JSON array in Javascript
body: <p>This question has been asked a couple of time here, but I haven't seen any of the responses work for me. </p>
  
  <p>I have this piece of code built with cakePHP which successfully returns the data in JSON format, but I haven't been able to insert this JSON data into HTML div using Javascript.</p>
  
  <pre><code>$('.book-click').click(function (e) {
      e.preventDefault();
      var getHotel = $(this).attr('hotel-id');
  
      $.ajax({
          type: "POST",
          url: "&lt;?php echo $this-&gt;Html-&gt;URL(array('action' =&gt; 'postBook')); ?&gt;",
          data: {
              hotel: getHotel
          },
          cache: false,
          dataTye: "json",
          success: function (JSONObject) {
              var myData = "";
              for (var key in JSONObject) {
                  if (JSONObject.hasOwnProperty(key)) {
                      myData += JSONObject[key];
                  }
              }
              /*console.log(myData);*/
              alert(myData[key]["hotelname"]); //Giving undifined in alert
  
          }
      });
  });
  </code></pre>
  
  <p>And this is the JSON data I get when I log the data on browser console:</p>
  
  <pre><code>[
      {
          "id": "11",
          "hotelname": "Sheraton hotel",
          "hoteladdress": "Abule Ikeja",
          "state": "Lagos State",
          "lga": "Ikeja",
          "hotelphone": "65645545454",
          "hotelwebsite": "",
          "adminphone": "6565656565",
          "adminemail": "mail@hotel.com",
          "hotelemail": "",
          "facilities": ",,",
          "roomscategory": "Diplomatic",
          "standardrate": "150000",
          "leanrate": "",
          "aboutHotel": "",
          "requestStatus": "0",
          "createdOn": "1424360902",
          "updatedOn": "1424360902"
      }
  ]
  </code></pre>
  
  <p>How do I successfully, get this JSON data into HTML. Something like this:</p>
  
  <pre><code>$('#myDiv').html(myData[key]["hotelname"]);
  </code></pre>
  
  <p>I tried this, but it's just giving me <code>Undefined</code>.</p>
  
  <p>Any help is appreciated.</p>