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 :

http://jsfiddle.net/qvaw3/48/

my json output :

enter image description here

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:

1.retrieve json file server

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/

  1. http://jquery-howto.blogspot.in/2009/04/twitter-jsonjsonp-api-url.html

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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -