A
A
Anton2016-03-25 15:19:52
JavaScript
Anton, 2016-03-25 15:19:52

Why doesn't $.getJSON work?

The index.html header has this:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="js.js"></script>


In js.js wrote this:
(function() {
    $(document).ready(function(){
        $.getJSON('data.json', function(json) {
            console.log(json);
        });
    });
})();


The browser shows that how the data.json resource appears, that is, it finds it, loads it. But nothing in the body of getJSON fires. even the banal alert('test');

What could be the problem? This example appears on all possible resources. And it even works for them (in the demo). This is absolute plagiarism, but it doesn't work for me...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2016-03-25
@hummingbird

The problem was the fucking comma... Let's break up.

M
Mikhail Abroskin, 2016-03-25
@miker059

such requests work only on the server, if you just run it on a computer without a server, it will not work, as far as I remember...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question