In my node js file, I have this code:
var jqxhr = $.getJSON( "favs.json", function() {
console.log( "success" );
})
.done(function() {
console.log( "second success" );
})
.fail(function( jqxhr, textStatus, error ) {
var err = textStatus + ", " + error;
console.log( "Request Failed: " + err );
})
.always(function() {
console.log( "complete" );
});
And in the server there is a file called favs.json in the same directory as the above js file. However when I visit the page, I get the error:
Request Failed: error, Protocol not supported.
Does anyone know whats wrong?
Thanks.
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,
http://localhost/favs.json.)Apparently $.getJSON uses an unexpected (possibly null) value as the protocol when it's not specified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With