【发布时间】:2019-03-12 06:35:35
【问题描述】:
我正在尝试使用 JavaScript/Node.js 构建控制台应用程序,以下 script.js 在编译时会抛出 ReferenceError: $ is not defined:
//user input from command line
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("Would you like to see which Car Types are available? Please type yes/no ", function(answer) {
// if yes, print search results to console in descending price order
if (answer === 'yes'){
var results= "";
$.getJSON("https://techtest.rideways.com/dave/?pickup=3.410632,-2.157533&dropoff=3.410632,-2.157533", function(data){
results = JSON.parse(data);
});
console.log("The following Car Types are available:", results.options['car_type'], " - ", results.options['price']);
}else{
console.log("No worries, have a nice day!");
}
rl.close();
});
如本文所示; ReferenceError: $ is not defined 我希望是因为我缺少 JS 库。
有没有一种方法可以在我的 script.js 中调用 JS 库而无需创建单独的 HTML 文件?由于我没有构建前端 Web 应用程序,因此看不到创建 HTML 文件的意义吗?
【问题讨论】:
-
你正在使用 Nodejs。将 jquery 与 require 一起使用。像 var $ = require('jquery');
标签: javascript jquery node.js compiler-errors