简体   繁体   English

TypeError:无法读取未定义的属性“ id”

[英]TypeError: Cannot read property 'id' of undefined

I am trying to post data into nodejs server from a html file sent data below are my html file and nodejs file i am getting above type error please help 我正在尝试从html文件中将数据发布到nodejs服务器中,发送的数据如下是我的html文件和nodejs文件,我正在获取上述类型错误,请帮助

in script code i am sending data from html file to nodejs server 在脚本代码中我正在将数据从html文件发送到nodejs服务器

Index.html file Index.html文件

<html>
<head>
<title>contacts</title>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">  </script>


<script>
$(document).ready(function(){




     var id,name,phone,email;
   $("#save").click(function(){

       id=$("#id").val();
       name=$("#name").val();
       phone=$("#phone").val();
       email=$("#email").val();
        $.post("http://localhost:8083/save",{id:id,name:name,phone:phone,email:email},function(data){



        });
    });
});
</script>

</head>

<body>
  <div id="a">
  </div>
<form class="form-horizontal">
  <div class="form-group">
    <label for="exampleInputID" class="col-sm-2 control-label">ID</label>
    <input type="ID" class="form-control" id="id" placeholder="ID">
  </div>
  <div class="form-group">
    <label for="exampleInputName" class="col-sm-2 control-label">Name</label>
    <input type="Name" class="form-control" id="name" placeholder="Name">
  </div>
 <div class="form-group">
    <label for="exampleInputPhone" class="col-sm-2 control-label">Phone</label>
    <input type="Phone" class="form-control" id="phone" placeholder="Phone">
  </div>
  <div class="form-group">
    <label for="exampleInputEmail1" class="col-sm-2 control-label">Email address</label>
    <input type="email" class="form-control" id="email" placeholder="Email">
  </div>




  <input id='save' type="button" value="save"  >
</form>

 <input type="button" id='get' value="Get" style="float: right;">
 </div>
</body>

</html>

Nodejs File


var express = require('express');
var app = express();
var http = require("http");
var mysql =  require('mysql');
var connection =  mysql.createConnection({
    host : 'localhost',
 user : 'root',
 password:''
});

connection.connect();

connection.query('use mysql');
var strQuery = 'select * from Person';
 app.use(express.static(__dirname + '/../Desktop'));


 app.post('/save',function(req,res){
  //res.setEncoding('utf8');
  var user_id=JSON.stringify(req.body.id);
  var user_name=JSON.stringify(req.body.name);

// this is my post request above



  console.log("ID = "+user_id+", name is "+user_name+", phone no. is "+user_phone+", email is "+user_email);

});

 app.listen(8083);
console.log('server running\n');

Here is your problem : 这是你的问题:

 <input type="ID" class="form-control" id="id" placeholder="ID">

There is not such type="ID" still available for input tag. 没有这样的type="ID"仍可用于输入标签。 for valid type of input tag, you ca refer http://www.w3schools.com/html/html_form_input_types.asp 有关输入标签的有效类型,请参阅http://www.w3schools.com/html/html_form_input_types.asp

There are some HTML5 added several new input types: HTML5中添加了一些新的输入类型:

color
date
datetime
datetime-local
email
month
number
range
search
tel
time
url
week

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

相关问题 UnhadledPromiseRejectionwarning:类型错误:无法读取未定义的属性“id” - UnhadledPromiseRejectionwarning: TypeError: Cannot read property " id' of undefined TypeError:无法读取nodejs中未定义的属性“ id” - TypeError: Cannot read property 'id' of undefined in nodejs TypeError:断开连接时无法读取未定义的属性“id” - TypeError: Cannot read property 'id' of undefined on disconnect Jest TypeError:无法读取未定义的属性“id” - Jest TypeError: Cannot read property 'id' of undefined TypeError:无法读取未定义错误的属性“_id” - TypeError: Cannot read property '_id' of undefined error JavaScript TypeError:无法读取未定义的属性“ id” - JavaScript TypeError: Cannot read property 'id' of undefined TypeError:无法读取未定义 ReactJs 的属性“_id”? - TypeError: Cannot read property '_id' of undefined ReactJs? TypeError:无法读取未定义的属性“ id”(用户未定义) - TypeError: Cannot read property 'id' of undefined (User is undefined) 未处理的拒绝(TypeError):无法读取未定义的属性“ id” - Unhandled Rejection (TypeError): Cannot read property 'id' of undefined 在浏览器刷新时出现错误“TypeError:无法读取未定义的属性“id” - Getting error 'TypeError: Cannot read property 'id' of undefined' on browser refresh
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM