this question has answer here:
- origin not allowed access-control-allow-origin 21 answers
- ways circumvent same-origin policy 11 answers
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.
- first have same-origins problem, which has been addressed elsewhere,
- second, have poorly formatted json in json file, ,
- 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
Post a Comment