javascript - Finding the error in my code for parsing JSON -
i've googled hours , checked documentation, can't seem find what's wrong jquery... i'm trying practice reading local json file , displaying contents in html's body.
$(document).ready(function(){ $.getjson( "test.json", function( data ) { var items = []; $.each( data, function( key, val ) { items.push( "<li id='" + key + "'>" + val + "</li>" ); console.log(data); }); $( "<ul/>", { "class": "my-new-list", html: items.join( "" ) }).appendto( "body" ); }); });
and heres actual json file in same folder:
{ "one": "singular sensation", "two": "beady little eyes", "three": "little birds pitch doorstep" }
i blank body when open index.html. index.html has
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript" src="script.js"></script>
so know shouldn't problem linking....
update: heres new output console now:
xmlhttprequest cannot load file:///c:/users/steven/desktop/meltapplication/test.json. received invalid response. origin 'null' therefore not allowed access.
//: means use same schema of current page, if have opened file locally (if url in address bar file://...), schema file://, script jquery on local machine error indicates.
do @melvinr said load jquery properly, can continue debugging rest of code.
Comments
Post a Comment