Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我想使用jquery从数据库中选择值并在同一页面上返回_Javascript_Jquery_Html_Mysql_Node.js - Fatal编程技术网

Javascript 我想使用jquery从数据库中选择值并在同一页面上返回

Javascript 我想使用jquery从数据库中选择值并在同一页面上返回,javascript,jquery,html,mysql,node.js,Javascript,Jquery,Html,Mysql,Node.js,这是post方法的节点API编码,它将从mysql数据库返回数据 // these my post method app.post('/home/product',function (req,res) { var data = { name:req.body.name }; con.getConnection(function(err,connect) { if (err) throw err; connect.query("SELECT

这是post方法的节点API编码,它将从mysql数据库返回数据

 // these my post method
 app.post('/home/product',function (req,res) {
   var data = {
      name:req.body.name
   };
   con.getConnection(function(err,connect) {
      if (err) throw err;
      connect.query("SELECT price,quantity from product WHERE name = ?",data.name,function 
      (err, result, fields) {
         if (err) throw err;
         res.send(result);
         connect.release();
      });
   });
 //con.end();
});
我想从html输入框中读取值并调用AJAX函数

// this is the html-element
<input class="fname" id="product" name="product" placeholder="Product 
      name"style="width:80%"/>
<button id="btncheckproduct">check</button>
<input type="text" name="priceperunit" id="priceperunit">
<input type="text" name="availableproduct" id="availableproduct">
有一个AJAX脚本,它将在另一个文本框中获取输入和返回值

// Ajax Script
<script type="text/javascript"> 
$(document).ready(()=>{
  $('#btncheckproduct').click(()=>{
    $.ajax({
      type: 'POST',
      data: {
         name:$("#product").val()
        },
      url: '/home/product',
      dataType: FormData,
      success:(data) => {
          //console.log(data);
          $('#priceperunit').val(data[0].price);
          $('#availableproduct').val(data[0].quantity);
        }
    });
  });
 });
</script>
我只想在文本字段中根据给定的名称返回值,但没有得到实际值


当我开始运行它的时候。它没有调用POST方法,也没有返回,但当我更改方法以获取其返回值时,而不是在POST情况下

您是否可以添加更多关于您得到的错误的详细信息,在html中,您还需要添加两个id为“priceperunit”和“availableproduct”的inputs/div元素,以便结果显示数据库中产品的价格和数量。您遇到了什么问题?你说你想做一个,然后展示你是如何做的;但是,当我运行它时,没有描述什么不起作用,或者你试图做什么。它不是调用POST方法,也不是返回,而是在我更改方法以获取其返回值时,而不是在POST的情况下