Getting protocol not supported when using getJSON on Node js on static json file
And in the server there is a file called favs.json in the same directory as the above js file.
If the file is located on server, why don't you just read it with fs.readFile()
?
var fs = require('fs');var fileContents;fs.readFile('./favs.json', function (err, data) { if (err) throw err; fileContents = data; // ...});
If you really want to get the contents of that file using XMLHttpRequest
,
- Make sure it is accessible via an HTTP(S) server in your application.
- Enter the full URL to the file you want to fetch (ex.
http://localhost/favs.json
.)
Apparently $.getJSON
uses an unexpected (possibly null) value as the protocol when it's not specified.