title: TypeError: Cannot read property 'id' of undefined in nodejs
body: <p>I'm struggling to make a function which selects from database based on the id entered in a textbox. I wrote the code, but it shows in console this error and I can't figure why: <code>TypeError: Cannot read property 'id' of undefined</code>.</p>
  
  <p>Code I have so far:</p>
  
  <p><strong>Client-side:</strong></p>
  
  <pre><code>function select()
              {
                  var id = $('#nr_reg').val();
                  $.ajax({
                      type: 'post',
                      url: '/id',
                      data : {
                          id: id
                      },
                      succes: function(data){
                          var id = data.id;
                          alert(id);
                          $('#optic').val(id);
                      },
                      error: function(err){
                          console.log(err);
                      }
  
                  }); 
              }
  </code></pre>
  
  <p><strong>Server-side:</strong></p>
  
  <pre><code>app.post('/id', function(req,res) {
  
      var data = req.body;
      var id = data.id;
      console.log(id);
      var query = "SELECT * FROM Control WHERE id=" +id;
      connection.query(query, function(error, result) {
              console.log(result);
              res.send(result);
      });
  });
  </code></pre>
  
  <p><strong>L.E:
  Function select:</strong></p>
  
  <pre><code>function select()
              {
  
                  var id = $('#nr_reg').val();
                  $.ajax({
                      type: 'post',
                      dataType: 'json',
                      url: '/id',
                      data : {
                          id: id
                      },
                      success: function(data){    
                          data = JSON.parse(data);                    
                          var id = data.id;
                          alert("merge");
                          $('#optic').val(id);
                      },
                      error: function(err){
                          console.log(err);
                      }
  
                  }); 
              }
  </code></pre>