旧行李 2013-09-26 17:53 采纳率: 25%
浏览 24

node.js中的变量查询

I am trying to modify a query on my server side (node.js) that looks like this:

var http = require('http');
var query = "SELECT * FROM Users WHERE Email='Test.User@TestUser.com'";

This is the hardcoded query. I'm trying to do something like this (email being a variable pulled in from an input text area in an HTML doc):

var http = require('http');
var query = "SELECT * FROM Users WHERE Email=" + "'" + email + "'";

I'm using JQuery to handle the request like this from a javascript file:

$.ajax({
        url: "http://127.0.0.1:8000/",
        type: "POST",
        success: function(dataRcvd) {
            alert(dataRcvd);
        }

If I figure out how to do this I can dynamically update the var query with different SQL queries/stored procedures.

  • 写回答

2条回答 默认 最新

  • 笑故挽风 2013-09-26 18:51
    关注
    // server.js
    var http = require('http');
    function handler(req, res){
      console.log('Server got '+req.body.email);
      var query = "SELECT * FROM Users WHERE Email=" + "'" + req.body.email + "'";
      someAsyncSQLCall(query, function(rows){
        res.send(200, rows);
      });
    };
    
    http.createServer(handler).listen(3000);
    
    //client.js
    $.ajax({
            url: "http://127.0.0.1:8000/",
            type: "POST",
            data: {email: 'value' },
            success: function(dataRcvd) {
                alert(dataRcvd);
            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决