Razvan Zamfir Razvan Zamfir - 3 months ago 54
Ajax Question

jQuery JSON parser: "Unexpected identifier" error

I have made a small (test) script that parses a JSON file (I use https://jsonplaceholder.typicode.com in the example below) and makes table rows out of the resulting object.

I am trying to append these rows to a table.

See the jsFiddle HERE.

I get an

Unexpected identifier
error that I find inexplicable. What am I doing wrong?

UPDATE: See my updated fiddle HERE. Thanks to all that helped.

Answer Source

You were appended the data wrong way. Replace your this portion of code by this.

var root = 'https://jsonplaceholder.typicode.com';
var tableRow = '';
  url: root + '/users',
  method: 'GET',
  success: function(data) {
    for (var i = 0; i < data.length; i++) {
      var tableRow = '<tr><td>' + data[i].name + '</td><td>' + data[i].email + '</td><td>' + data[i].email + '</td></tr>';
  error: function() {
    var tableRow = '<tr><td>There is no data to display</td></tr>';
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table" id="dataTable">
      <th>Full Name</th>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download