请求" _id。$ oid"的未知参数

时间:2016-03-24 07:47:11

标签: javascript jquery datatables mlab

我尝试使用jQuery和datatables在mongodb中添加新的学生数据。当我点击"提交"按钮此错误显示在警告框中"请求第1行第0列和第34行的" _id。$ oid的未知参数。 这是我的jQuery代码:

  $("#btnSubmit").on("click", function(e){
e.preventDefault();
var objc = {
  Full_Name: $("#fullName").val(), // get value from textbox
  Degree: $("#programDegree").val(), // get value from textbox
  Session: $("#programSession").val(), // get value from textbox
  edit: "Edit",
  del: "Delete"
  };
$.ajax({
    type: 'POST',
    url: "https://api.mongolab.com/api/1/databases/mydb/collections/students?apiKey=ftIHhADklaeFUeTw4YzKZdlb_MWQYfGO",
    data: JSON.stringify(objc),
    contentType: "application/json; charset=utf-8",
    success: function(result){
      var oID = result._id.$oid;
      // console.log(oID);
      table.row.add( [
        oID,
        result.Full_Name,
        result.Degree,
        result.Session,
        result.edit,
        result.del
     ] ).draw();
  },
  error:function(res){
    console.log("Bad thing happend! " + res.statusText);
  }
});
$('#myModalNorm').modal('toggle');
$('#formID').trigger("reset");

这是我得到的回复ajax请求的对象。

Object {Full_Name: "Sufian", Degree: "CS", Session: "2008-2012", edit: "Edit", del: "Delete"…}
Degree: "CS"
Full_Name: "Sufian"
Session: "2008-2012"
_id: Object $oid: "56f39a62e4b0b7299e113da5"
__proto__: Object
del: "Delete"
edit: "Edit"

提前致谢。

0 个答案:

没有答案