javascript - JQuery not returning any information for the JSON file -


this question has answer here:

i working on s3. in bucket have browser.json file, jquery.js, , index.html. in index.html writing script reads json file. here code looks like...

!doctype html> <html> <head>     <script type="text/javascript" src="jquery.js"></script> </head> <body>     <script>         $.getjson('https://s3.amazonaws.com/plxscreenshots/browser.json', function(data) {             alert(data.date)         });     </script>     <p> hope works!</p> </body> 

i still pretty new html/javascript feel should working , not, suggestions?

so have couple of issues going on here.

  1. first have same-origins problem, which has been addressed elsewhere,
  2. second, have poorly formatted json in json file, ,
  3. third don't have value1 property.

i expect json file more this:

{"date": "2013-07-19", "value1": 5678 }  

notice how both keys and date quoted? in json, have quote isn't number, object ([] , {}), or boolean (true or false). notice how there no trailing comma?

the first 2 problems cause error before feedback , because have no error handler, fail silently (though you're @ least seeing error in javascript console). can make little easier adding .error(function(a) { alert("error"); console.log(e); }) end of function. like:

$.getjson(<my-url>, function(data) {      alert(data.value1) }).error(function(a) { alert("error"); console.log(e);}); 

Comments