reading json data from a file

reading json data from a file

I am trying to read a JSON file from a file named sites.js which seems pretty straight forward but I can't get past an error event firing. Initially I did not tell the ajax() call the datatype, and that caused the data to get written to the console as an unrecognized expression.

sites.js as exported from mySQL:

  1. [
  2. {
  3. 'Database' : 'datasite',
  4. 'Table' : 'sites',
  5. 'IP' : '192.168.0.101',
  6. 'Server' : 'ria'
  7. },
  8. {
  9. 'Database' : 'datasite',
  10. 'Table' : 'columns',
  11. 'IP' : '192.168.0.101',
  12. 'Server' : 'ria'
  13. }
  14. ]
code to read and display:
  1. var manageSites = {
  2. data: [],
  3. getSites: function(){
  4. $.ajax({
  5. type : 'get',
  6. dataType: 'json',
  7. url : 'sites.js',
  8. cache : false,
  9. error : function(){$('#manage-sites').html("Sites not found")},
  10. success : function(data){
  11. manageSites.data = $(data);
  12. manageSites.showSites();
  13. }//end success function
  14. });
  15. },
  16. showSites : function(){
  17. var key = '';
  18. var htm = '<table><thead><tr>';
  19. for(i=0; i< 1; i++){
  20.    for (key in manageSites.data[0]){
  21.        htm +='<th style="font-size:10pt;">' + key + '</th>'
  22.    }
  23.     htm += '<th style="font-size:10pt;">Remove</th></tr></thead><tbody>'
  24. };
  25.    for(i=0; i<data.length; i++){
  26.    htm +='<tr>';
  27.    htm +='<td>' + manageSites.data[i].Database + '</td>';
  28.    htm +='<td>' + manageSites.data[i].Table + '</td>';
  29.    htm +='<td>' + manageSites.data[i].IP + '</td>';
  30.    htm +='<td>' + maangeSites.data[i].Server + '</td>';
  31.    htm +='<td style="text-align:center;"><input type="checkbox"></td>';
  32.    htm +='</tr>';
  33.      
  34. };
  35. htm +='</tbody></table>';
  36. $('#manage-sites').html(htm);
  37. }
  38.        
  39. }

When I execute this after adding the dataType I get "Error sites not found", which is what is supposed to happen when something doesn't work.  In my mind I was thinking this would fire if the file couldn't be found, but that's not what is triggering the error to fire here.  Any insight is appreciated.