0

I am creating a web app in nodejs with MySQL Db. 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.

Here is the form i m using in 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. But I am not able to understand how to make this call n Bluemix using Nodejs an MySQL. After doing some research and trying out the starter kit, I understood that the servlet related code should be put in app.js file. 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.

Ann
  • 15
  • 7
  • For others who come along - [here](http://stackoverflow.com/questions/5818312/mysql-with-node-js) is a link to another similar question that explains how to connect and query with Node.js and MySQL. – Andrew Lohr Apr 20 '15 at 14:38

1 Answers1

0

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) {

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

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

Hope it helps.

diwesh
  • 294
  • 1
  • 9
  • Hi Diwesh, Thanks for your reply. I found a way to connect to SQL DB from app.js file. I think I will use that since I don't know MongoDB. – Ann Nov 19 '14 at 18:11
  • @Ann could you please accept an answer so we can close this out? – Jeff Sloyer Mar 06 '15 at 13:24