title: Simple ajax request
body: <p>I am new to ajax and am trying to get the following script working. I just want to take info from a json object and print it to the document. </p>
  
  <p>Here is the JSON file called companyinfo.json:  </p>
  
  <pre><code>{
  'id':1,
  'name':'Stack'
  
  
  }
  </code></pre>
  
  <p>The Ajax request looks like this:</p>
  
  <pre><code>ar xhr = false;
  var xPos, yPos;
  
  $(function(){
  
      var submitButton = $("#dostuff");
      submitButton.onclick = sendInfoRequest;
  
  });
  
  function sendInfoRequest (evt) {
      if (evt) {
          var company1 = $("#companyInput1").val;
          var company2 = $("#companyInput2").val;
      }
      else {
          evt = window.event;
          var company = evt.srcElement;
      }
      $.ajax({
          url : 'companyinfo.json',
          dataType: 'json',
          data: company1,
          success: function(data) {
              console.log(data);
              var items = new Array ();
              $.each(data, function(key, val) {
                  items.push('&lt;li id="' + key + '"&gt;' + val + '&lt;/li&gt;');
              });
          }
  
      });
  
  
      return false;
  }
  console.log(data.id);
  </code></pre>
  
  <p>To start simple. I just console.log the data.id to see if the script returned a value from the json file.</p>
  
  <p>To write it to the document I would do something like this, calling the showContents function in the callback function above:</p>
  
  <pre><code>function showContents(companyNumber) {
      if (xhr.readyState == 4) {
          if (xhr.status == 200) {
              var outMsg = xhr.responseXML;
              $("." + data.companyName.toLowerCase + companyNumber).innerHTML(data.companyName)
          }
          else {
              var outMsg = "There was a problem with the request " + xhr.status;
          }
  
  
      }
  }
  </code></pre>
  
  <p>I'm pretty new to Ajax, but hopefully that makes some sense. Thanks</p>