在我的node js文件中,我有以下代码:
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" );
});
在服务器中,有一个文件favs.json
与上述js文件位于同一目录中。但是,当我访问页面时,出现错误:
Request Failed: error, Protocol not supported.
有人知道怎么了吗?
谢谢。
在服务器中,与上述js文件位于同一目录中的文件名为favs.json。
如果文件位于服务器上,为什么不随便阅读fs.readFile()
?
var fs = require('fs');
var fileContents;
fs.readFile('./favs.json', function (err, data) {
if (err) throw err;
fileContents = data;
// ...
});
如果您确实想使用来获取该文件的内容XMLHttpRequest
,
http://localhost/favs.json
。$.getJSON
未指定时,显然使用意外的值(可能为null)作为协议。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句