title: Getting an error function doing ajax call once I put this variable in
body: <p>For some reason, I keep getting error function in ajax call whenever I put this <code>"ntaReqRef": ntaReqRef</code> but when I don't include it my ajax call works perfectly so I am stuck as to whether it is illegal or does it have to do with my code  because when I execute the code, it shows the correct response in node.js but then gives an error function.</p>
  
  <pre><code>function create(){
  var samId = $('#samIda').val();
  var itemDescrip = $('#itemDescrip').val();
  var issueQty =$('#issuedQty').val();
  var openQty = $('#openingQty').val();
  var closeQty = $('#closingQty').val();
  var corrupQty = $('#corruptedQty').val();
  var remarks = $('#Remarks').val();
  var ntaReqRef = $('#ntaReqRefa').val();
  var postData = { 
                  "samId": samId ,  "itemDescrip": itemDescrip, "issueQty" : 
                   issueQty,"openQty" : openQty, "closeQty" :closeQty, 
                  "corrupQty": corrupQty, "remarks": remarks, "ntaReqRef": 
                   ntaReqRef 
                  };
  var postJSON = JSON.stringify(postData);
  $.ajax({
      url: "http://localhost:3000/api/insertRecord", // server url
      type: "POST", //POST or GET
      contentType: "application/json", // data to send in ajax format or querystring format
      data: postJSON,
      dataType : "json", //dataType is you telling jQuery what kind of 
    response to expect
      success: function(response) {
          alert('success');
           $("#Iresult").html("A record has been created. :D");
      },
      error: function(response) {
          alert('error' + response);
      }
  });
  }
  </code></pre>
  
  <p>My html code regarding the variable that has problems.</p>
  
  <pre><code>    &lt;div class="field-wrap"&gt;
          &lt;label&gt;
            NTA SAM Ref Number&lt;span class="req"&gt;*&lt;/span&gt;
          &lt;/label&gt;
          &lt;input type="NtaReqRef" id="ntaReqRefa" name= "ntaReqRef" required 
          autocomplete="off"/&gt;
        &lt;/div&gt;
         &lt;input class="button" type="submit" id="insert" value="Create" 
         onclick="create()" /&gt;
        &lt;/form&gt;
        &lt;div id= "Iresult"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>This is my server side code.</p>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  var url = 'mongodb://localhost:27017/myproject';
  var insertDocument = function(db, req, callback) { 
  db.collection('documents').insertOne({
  //'_id': Object.keys(obj).length,
      'samID': req.body.samId,
      'itemDescription': req.body.itemDescrip,
      'issuedQTY': req.body.issueQty,
      'openingQTY':req.body.openQty,
      'closingQTY':req.body.closeQty,
      'corruptedQTY':req.body.corrupQty,
      'Remarks':req.body.remarks,
      'ntaSamRequestRef': req.body.ntaReqRef
      //'Created Date': "&lt;b&gt;" + day + "/" + month + "/" + year + "&lt;/b&gt;"
  }, function(err, results) {
  //assert.equal(err, null);
      if(err) return callback(err);
      console.log("Inserted a document into the documents collection.");
      console.log(results);
      var cursor = db.collection('documents').find({
          //'_id': Object.keys(obj).length,
          'samID': req.body.samId
      }).toArray(function(err, doc) {
          if (err) {
              return callback(err);
          } else{
          console.log('Successfully queried');
          console.log(doc);
          return callback(null, JSON.stringify(doc));
          }
      });
   });
   };
   module.exports = {
   postCollection : function(req,res){
      var samId = req.body.samId;
      var itemDescrip = req.body.itemDescrip;
      var issueQty = req.body.issueQty;
      //var indexNo = Object.keys(obj).length;
      var openQty = req.body.openQty;
      var closeQty = req.body.closeQty;
      var corrupQty = req.body.corrupQty;
      var remarks = req.body.remarks;
      var ntaReqRef = req.body.ntaReqRef;
      //var createdDate =  "&lt;b&gt;" + day + "/" + month + "/" + year + "&lt;/b&gt;"
      MongoClient.connect(url, function(err, db) {
          //assert.equal(null, err);
          if(err) {
              res.send(err);
              res.end();
          }
          insertDocument(db, req, function(err,doc) {
              if(err)
                  res.send(err);
              else{
                  setTimeout(function(){
                      res.send(doc);
                      res.end();
                  },2000);
              }
              db.close();
          });
      });
  }
  }   
  </code></pre>
  
  <p>Any help is appreciated. Thanks in advance!</p>