title: jQuery AJAX to access REST API JSON data
body: <p>I created a REST API in my node.js, express.js application on <a href="http://localhost:3000/api/kfc" rel="nofollow">http://localhost:3000/api/kfc</a>. JSON data is available on it. The function that creates it...</p>
  
  <pre><code>router.get('/kfc', function(req, res, next) {
  var response=
  {
  "id":"123", 
  "name":"name1",
  "drink":"drink1"
  }
  res.end(JSON.stringify(response));
  });
  </code></pre>
  
  <p>I am accessing it using jQuery AJAX GET call from <a href="http://localhost:8887/kfc.html" rel="nofollow">http://localhost:8887/kfc.html</a> , The code for kfc.html and kfcLoad.js is-</p>
  
  <p>//kfc.html</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;h3&gt;Order Placed&lt;/h3&gt;
  &lt;ul id="ulOrder"&gt;
  
  &lt;script src="javascripts/jQuery.js"&gt;&lt;/script&gt;
  &lt;script src="javascripts/kfcLoad.js"&gt;&lt;/script&gt;
  &lt;/body&gt;    
  &lt;/html&gt;
  </code></pre>
  
  <p>//kfcLoad.js</p>
  
  <pre><code>$(function(){
  
  var $ulOrder=$('#ulOrder');
  
  function addOrder(order)
  {
      $ulOrder.append('&lt;li&gt;&lt;strong&gt;ID&lt;/strong&gt;: '+ order.id+'&lt;br&gt;&lt;strong&gt;Name&lt;/strong&gt;: '+ order.name+'&lt;br&gt;&lt;strong&gt;Drink&lt;/strong&gt;: '+order.drink+'&lt;br&gt;&lt;/li&gt;');
  }
  $.ajax({
      type: 'GET',
      url: 'http://localhost:3000/api/kfc',
      dataType: 'jsonp',
      success: function(orders){
  
          $.each(orders, function(i, order){
          addOrder(order);
          });
      },
      error: function(jqXHR, textStatus, errorThrown) {
          console.log(textStatus, errorThrown);
      }
  });
  });
  </code></pre>
  
  <p>I am getting errors-</p>
  
  <pre><code>jQuery.js:1 Uncaught SyntaxError: Unexpected token &lt;
  kfcLoad.js:1 Uncaught SyntaxError: Unexpected token &lt;
  </code></pre>