gpt4 book ai didi

mysql - Bluemix 云平台 : How to pass a value in node. js MySQL

转载 作者:行者123 更新时间:2023-11-29 23:25:34 25 4
gpt4 key购买 nike

我正在使用 MySQL Db 在 Nodejs 中创建一个 Web 应用程序。我想将用户输入值传递给 app.js 文件,它在数据库中使用该值进行搜索并在另一个页面中显示结果。

这是我在index.html中使用的表单:

<form method="get" action="SearchResults">
<input type="text" name="zipcode" placeholder="Search with ZipCode/City..."
required style = "width: 830px; height:20px">
<input type="submit" value="Submit"></center>
</form>

我知道如何使用 JSP 和 Servlet 进行 SearchResults 调用。但我无法理解如何使用 Nodejs 和 MySQL 在 Bluemix 中进行此调用。在做了一些研究并尝试了入门工具包之后,我了解到 servlet 相关代码应该放在 app.js 文件中。但我不确定如何编写数据库查询以及如何从数据库获取详细信息并显示到另一个页面上。任何帮助,将不胜感激。谢谢。

最佳答案

要检索数据,您需要实现如下逻辑:

  html/jade file:
// USER INFO
#userInfo
h2 User Info
p
strong Name:
| <span id='userInfoName'></span>
br
strong Age:
| <span id='userInfoAge'></span>
br
strong Gender:
| <span id='userInfoGender'></span>
br
strong Location:
| <span id='userInfoLocation'></span>
// /USER INFO

js中对应的函数代码://显示用户信息函数 showUserInfo(事件) {

// Prevent Link from Firing
event.preventDefault();

// Retrieve username from link rel attribute
var thisUserName = $(this).attr('rel');

// Get Index of object based on id value
var arrayPosition = userListData.map(function(arrayItem) { return arrayItem.username; }).indexOf(thisUserName);

// Get our User Object
var thisUserObject = userListData[arrayPosition];

//Populate Info Box
$('#userInfoName').text(thisUserObject.fullname);
$('#userInfoAge').text(thisUserObject.age);
$('#userInfoGender').text(thisUserObject.gender);
$('#userInfoLocation').text(thisUserObject.location);

};

以下是此内容的引用文档: http://cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/

应用程序在本地运行后,您可以通过 cloudfoundary 工具将其推送到 Bluemix 上: http://clouds-with-carl.blogspot.in/2014/02/deploy-minimal-nodejs-application-to.html

希望有帮助。

关于mysql - Bluemix 云平台 : How to pass a value in node. js MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27002126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com