I have js only project. i call from my static index.html file the json file content.
I try(not works):
$.getJSON('/js/test.json&callback=?',
function() {
alert('1111111111111111');
},'jsonp');
Edit get in chrome: XMLHttpRequest cannot load file:///somefolder/test/data.json. Origin null is not allowed by Access-Control-Allow-Origin
Thanks
I have js only project. i call from my static index.html file the json file content.
I try(not works):
$.getJSON('/js/test.json&callback=?',
function() {
alert('1111111111111111');
},'jsonp');
Edit get in chrome: XMLHttpRequest cannot load file:///somefolder/test/data.json. Origin null is not allowed by Access-Control-Allow-Origin
Thanks
Share Improve this question edited Apr 28, 2012 at 20:30 Ben asked Apr 27, 2012 at 14:50 BenBen 25.8k35 gold badges113 silver badges166 bronze badges 2- why the (&callback=?) looks wrong! – ilyes kooli Commented Apr 27, 2012 at 14:52
- the callback should be used for JSON-P requests – Fabrizio Calderan Commented Apr 27, 2012 at 14:53
2 Answers
Reset to default 2You are missing data variable in callback!
$.getJSON('/js/test.json', function(data) {
console.log('JSON data received:', data);
});
You can retrieve json from a local source, it doesn't need to be jsonp, and even if it did what you are doing is not how you do it.
$.getJSON('http://yours./js/test.json',
function() {
alert('1111111111111111');
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745138083a4613298.html
评论列表(0条)