user1662380
user1662380

Reputation: 87

update database using ajax in mvc3

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

Answers (2)

lavrik
lavrik

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

StaticVariable
StaticVariable

Reputation: 5283

here is the problem

data: myJsonObject,

use

data:{"jsondata":myJsonObject}

Upvotes: 0

Related Questions