Reputation: 87
var loginCred = new Object();
loginCred.Username = $('#userName').val();
loginCred.Password = $('#password').val();
loginCred.RememberMe = $('#rememberMe').checked;
var myJsonObject = JSON.stringify(loginCred);
$.ajaxSetup({ cache: false });
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Account/LogOnAjax/",
data: myJsonObject,
dataType: "json",
success: function(data) {
PostCredentialsSuccess(data);
}
});
I try to develop application using mvc3.In here i want to update database using ajax. this my ajax request to post a form data.But I want to catch this data in controller and update database using this data.Please help me
Upvotes: 0
Views: 780
Reputation: 1474
You don't need to stringify your object.
var myJsonObject = JSON.stringify(loginCred);
You have specified dataType: "json" so you can use loginCred
data: loginCred,
And try remove contentType: "application/json; charset=utf-8",
Upvotes: 1
Reputation: 5283
here is the problem
data: myJsonObject,
use
data:{"jsondata":myJsonObject}
Upvotes: 0