Reputation: 1457
Am trying to send integer type data in json and retrive in server side
in client side am sending in below code
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')
}
});
And in server side while i trying to print data am getting as
{ id: '1', password: 'qwer' }
actually am sending id as integer format but in server side am getting this as string.
How can i retrive { id: 1, password: 'qwer' }
.i want to pass this data to update a database.so i cant change it as { id: parseInt('1'), password: 'qwer' }.
In database id are stored in integer form.so due this problem cant update the db
also.
helper.update(context.db.Signups, data, function(err, res) {
console.log(res)
callback(null, {res:true});
});
Upvotes: 1
Views: 2886
Reputation: 71
you can add processData : false to the options section of your .ajax call.
Upvotes: 1