ajax - error on loading json data -


i trying load .json data web app , never can achieve success.

it returns error function.

here .js file:

 $(document).ready(function () {  var output = $('#stage');   $.ajax({      url: 'http://www.haverhill-ps.org/ios/app/data/calendar-json.json',      datatype: 'json',      timeout: 5000,      success: function (data) {          $.each(data, function (i, item) {              var eventinfo = '<h1>' + item.month + '</h1>' + '<p>' + item.date + '<br>' + item.time + '</p>';               output.append(eventinfo);          });      },      error: function () {          output.text('there error loading data.');      }  }); }); 

here json data:

{     "month": "june", //november     "date": "10", //10     "time": "5pm", //5pm }, {     "month": "july", //november     "date": "4", //10     "time": "1pm", //5pm } 

then, within html have div setup:

<div id="stage">run here...</div>   

the returned data not valid json.

your missing [and ] around result , comments not valid in json. , @ end of last element of each object invalid. can validate json @ e.g. http://jsonlint.com/

a valid json way:

[{     "month": "june",     "date": "10",     "time": "5pm" }, {     "month": "july",     "date": "4",     "time": "1pm" }] 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -