0
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

3
  • 2
    $('#rememberMe').checked; should be $('#rememberMe').is(':checked'); or $('#rememberMe')[0].checked; Commented Sep 28, 2012 at 13:42
  • So uh... your storing a username/password combination plain text in the dom? Commented Sep 28, 2012 at 13:45
  • Would you confirm whether data is posted to the Controller correctly?Share the "/Account/LogOnAjax/" Action code as well. Commented Sep 28, 2012 at 19:33

2 Answers 2

1

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",

Sign up to request clarification or add additional context in comments.

1 Comment

"And try remove contentType: "application/json; charset=utf-8"" that worked for me! Thanks
0

here is the problem

data: myJsonObject,

use

data:{"jsondata":myJsonObject}

2 Comments

This is not PHP. The server side should have a strongly typed model for the model binder to work against.
I want to action method how I manupulate json data in action method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.