简体   繁体   English

Bluemix Cloud Platform:如何在node.js MySQL中传递值

[英]Bluemix Cloud Platform: How to pass a value in node.js MySQL

I am creating a web app in nodejs with MySQL Db. 我正在使用MySQL Db在nodejs中创建一个Web应用程序。 I want to pass the user input value to app.js file where it makes a search in the database with that value and display results in another page. 我想将用户输入值传递给app.js文件,在其中使用该值在数据库中进行搜索并在另一页中显示结果。

Here is the form im using in index.html: 这是im在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>

I know how to make the SearchResults call using JSP and Servlets. 我知道如何使用JSP和Servlet进行SearchResults调用。 But I am not able to understand how to make this call n Bluemix using Nodejs an MySQL. 但是我不明白如何使用Nodejs和MySQL对Bluemix进行调用。 After doing some research and trying out the starter kit, I understood that the servlet related code should be put in app.js file. 在进行了一些研究并尝试了入门工具包之后,我了解到,与Servlet相关的代码应放在app.js文件中。 But I am not sure how to write the database query and how to fetch the details from database and display onto another page. 但是我不确定如何编写数据库查询以及如何从数据库中获取详细信息并显示在另一页上。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

For retieving data,you need to implement logic for that like below: 要重新整理数据,您需要实现以下逻辑:

  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

corresponding function code in js: // Show User Info function showUserInfo(event) { js中的相应功能代码://显示用户信息功能showUserInfo(event){

// 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);

}; };

Below is the reference doc for this: http://cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/ 以下是此文档的参考文档: http : //cwbuecheler.com/web/tutorials/2014/restful-web-app-node-express-mongodb/

Once you application is running locally,you can push it on Bluemix through cloudfoundary tool: http://clouds-with-carl.blogspot.in/2014/02/deploy-minimal-nodejs-application-to.html 一旦应用程序在本地运行,您就可以通过cloudfoundary工具将其推送到Bluemix上: http ://clouds-with-carl.blogspot.in/2014/02/deploy-minimal-nodejs-application-to.html

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM