使用jquery在json中作为ajax请求发送整数类型参数



我试图在json中发送整数类型数据并在服务器端检索

在客户端发送下面的代码

var userID = readCookie("user_id");
  var data = {
    "id": parseInt(userID),
    "password": $("#password").val()
  };
  $.ajax({
    type: 'post',
    url: "/changePassword",
    dataType: "json",
    data: data,
    success: function (response) {
      $("#errLabel").html('Password changed successfully')
    }
  });

在服务器端,当我试图打印数据得到

 { id: '1', password: 'qwer' }

实际上我发送id作为整数格式,但在服务器端我得到这个字符串。

如何检索{ id: 1, password: 'qwer' } .我想传递这个数据来更新数据库。所以我不能把它改成{ id: parseInt('1'), password: 'qwer' }.在数据库中,id以整数形式存储。因此,由于这个问题不能更新db也。

helper.update(context.db.Signups, data,  function(err, res) {
console.log(res)
 callback(null, {res:true});
 });

您可以将processData: false添加到.ajax调用的options部分。

最新更新