I have simple JSON File(map.json) located on desktop ..running on localHost perfectly(see screenshot)
I tried many Solution to get it access with $.ajax but not getting success .I also tried with $.getJSON .. Still no luck
here is my 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 is present on the requested resource. Origin 'http://fiddle.jshell.net' is therefore not allowed access."
I searched this post
Why am I seeing an "origin is not allowed by Access-Control-Allow-Origin" error here?
it says use jsonop and dataype .. I used that in my fiddle . still same error ..
and this post
2.$.getJSON not working with local JSON file
Solution says
2.1Use Firefox or run it on a webserver ;) --Not working
2.2 add "Origin null is not allowed by Access-Control-Allow-Origin" in Chrome. -
--- I did by this post
https://in.answers.yahoo.com/question/index?qid=20110807065538AAs4Wog-->
It is not allowing me to add in chrome shortcut
What other things I tried:
1.retrieve json file from server
Solution says use $.getJSON .. I tried still not working(example in upper fiddle link) 2. $.getJSON not working with local JSON file
Solution says use datatype as 'jsonop' .. I also tried that .. No working here is jsfiddle for jsonop
http://jsfiddle.net/yvzSL/905/
Solution says add callback with parameter in url .. my URL dont have such
What can I search for more?
Edit: finally found one extension which removed my error.