0

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

2
  • why the (&callback=?) looks wrong! Commented Apr 27, 2012 at 14:52
  • the callback should be used for JSON-P requests Commented Apr 27, 2012 at 14:53

2 Answers 2

2

You are missing data variable in callback!

$.getJSON('/js/test.json', function(data) {
    console.log('JSON data received:', data);
});
Sign up to request clarification or add additional context in comments.

2 Comments

not working! i use jsonp because i access local file without server that run it.
XMLHttpRequest cannot load file:///somefolder/test/data.json. Origin null is not allowed by Access-Control-Allow-Origin.
2

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.com/js/test.json',
   function() {
   alert('1111111111111111');
});

3 Comments

not working! i use jsonp because i access local file without server that run it.
XMLHttpRequest cannot load file:///somefolder/test/data.json. Origin null is not allowed by Access-Control-Allow-Origin.
The file has to be on the same domain as the request.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.