When I encode this in some file (say: test.html):
<html>
<head>
<title>Test</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$.getJSON('https://newsapi.org/v1/articles?source=techcrunch&sortBy=top&apiKey=my-api-key',function(json) {
console.log(json);
});
</script>
</body>
</html>
But if I do the same in another file, say (main.js)
(function(){
$.getJSON('https://newsapi.org/v1/articles?source=techcrunch&sortBy=top&apiKey=my-api-key',function(json) {
console.log(json);
});
});
The above code does not display JSON data on the console, I added main.js in the HTML.
source
share