最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

如何根据用户表单输入查询api

运维笔记admin12浏览0评论

如何根据用户表单输入查询api

如何根据用户表单输入查询api

我有一个节点应用程序,在其中我要调用Google Places api并将该数据发送到前端。在前端,我有一个发布到节点服务器的基本表单。我想根据用户表单输入从api调用返回数据。

我能够将表单发布到服务器,并且可以在请求对象中看到数据,但是我在弄清楚如何使用这些数据基于表单输入正确查询api时遇到了麻烦。

表格

 <form method="post" class="form" action="http://localhost:3005/dyno">
<fieldset class="form-fieldset ui-input __first">
  <input type="text" name="interests" id="username" tabindex="0" />
  <label for="intrests">
    <span data-text="Interests">Intrests</span>
  </label>
</fieldset>

<fieldset class="form-fieldset ui-input __second">
  <input type="text" name="location" id="email" tabindex="0" />
  <label for="location">
    <span data-text="Location">Location</span>
  </label>
</fieldset>

  <input type="submit" value="Submit" />
  </form>

记录我需要的数据的服务器端代码

app.post('/dyno', function(request, response){

console.log(request.body.interests)
console.log(request.body.gender)

response.end()

});

API调用

 _EXTERNAL_URL = `.663918,-73.8820044&radius=2500&type=gyms&keyword=fitness&key=${KEY}`;

app.get('/ruckus',(req, res) => {
request(_EXTERNAL_URL, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) 
res.send(body) 
}
});
})

如何根据用户输入的表单数据基于半径,类型和关键字参数返回数据?

回答如下:

因为我需要在前端渲染数据

发布评论

评论列表(0)

  1. 暂无评论