javascript - Cannot access json file from localhost -
i have simple json file(map.json) located on desktop ..running on localhost perfectly(see screenshot)
i tried many solution access $.ajax not getting success .i tried $.getjson .. still no luck
here fiddle :
my json output :
my code sample
var url = 'http://localhost/map.json'; $.getjson("http://localhost/map.json", {}, function (data) { $.each(data.items, dosomething1); alert('success') }); $.ajax({ type: 'get', url: url, async: false, contenttype: "application/json", datatype: 'json', success: function (data) { alert(this.url); //console.log(data); },
chrome console says .."xmlhttprequest cannot load http://localhost/map.json. no 'access-control-allow-origin' header present on requested resource. origin 'http://fiddle.jshell.net' therefore not allowed access."
i searched post
why seeing "origin not allowed access-control-allow-origin" error here?
it says use jsonop , dataype .. used in fiddle . still same error ..
and post
2.$.getjson not working local json file
solution says
2.1use firefox or run on webserver ;) --not working
2.2 add "origin null not allowed access-control-allow-origin" in chrome. -
--- did post
https://in.answers.yahoo.com/question/index?qid=20110807065538aas4wog-->
it not allowing me add in chrome shortcut
what other things tried:
solution says use $.getjson .. tried still not working(example in upper fiddle link) 2. $.getjson not working local json file
solution says use datatype 'jsonop' .. tried .. no working here jsfiddle jsonop
http://jsfiddle.net/yvzsl/905/
solution says add callback parameter in url .. url dont have such
what can search more?
edit: found 1 extension removed error.
you have found answer, don't know yet: have set webserver.
your browser doesn't understand url file:///c:/users/neeraj/desktop/map.json
. have @ whatever server appropriate system... or if have personal website, put json file on server , point url file.
also, read errors in console. tend pretty clear on going on - chrome gives following error cross origin requests supported protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource
.
Comments
Post a Comment