[英]how to send API request based on users input
I am new to java script and node JS.我是 java 脚本和节点 JS 的新手。 I am trying to create a simple app where the user can convert currency values by entering the amount and the currency type.
我正在尝试创建一个简单的应用程序,用户可以通过输入金额和货币类型来转换货币值。 i checked this API request its working fine, but i have no idea how to use html input tag to get the inputs and send it to the API request form.
我检查了这个 API 请求它工作正常,但我不知道如何使用 html 输入标签来获取输入并将其发送到 API 请求表。
var unirest = require("unirest");
var req = unirest("GET", "https://currency-exchange.p.rapidapi.com/exchange");
req.query({
"q": "1",
"from": "USD",
"to": "LKR"
});
req.headers({
"x-rapidapi-host": "currency-exchange.p.rapidapi.com",
"x-rapidapi-key": "1599d15183msh1ede0c59134d7c4p1c921bjsnedcdcb4dded9"
});
req.end(function (res) {
if (res.error) throw new Error(res.error);
console.log(res.body);
});
Node.js is not a web browser. Node.js 不是 web 浏览器。 It doesn't have input tags.
它没有输入标签。
If you want to communicate between a browser and Node.js then you'll need to create some kind of connection between them.如果您想在浏览器和 Node.js 之间进行通信,那么您需要在它们之间创建某种连接。
Typically this would involve writing a web service using Node.js (eg with the Express module ) and then communicating to it with a form submission or with an Ajax request .通常,这将涉及使用 Node.js(例如使用Express 模块)编写 web 服务,然后通过表单提交或Ajax 请求与其通信。
Alternatively, you could bundle Node.js and the browser together into a single app.或者,您可以将 Node.js 和浏览器捆绑到一个应用程序中。 Electron is a populate framework for doing that.
Electron是一个用于执行此操作的填充框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.