weixin_33711641 2019-04-24 10:24 采纳率: 0%
浏览 66

$ .ajax数据为空

I need to save the record in the database. I have been doing this thing but I don't know for what reason it is giving me this error. Any help will be appreciated. I don't know why the data is null. Please refer to the error show in below screenshot:

data is not defined

data is undefined.

 function submit(amount) {
    var _url = ' /Home/SaveDepositedAmount';
    console.log(_url);
    $.ajax({
        type: "POST",
        async: false,
        cache: false,
        beforeSend: function () { ShowLoading(); },
        url: _url,
        processData: false,
        contentType: false,
        dataType: 'json',
        data: { amount: amount },
    })
    .done(function (data) {

Server side code is:

    [HttpPost]
    public JsonResult SaveDepositedAmount(int amount)
    {
        JsonResult result = new JsonResult();
        int userId = Authentication.Instance.User.UserId;
        result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
    }
  • 写回答

2条回答 默认 最新

  • weixin_33743248 2019-04-24 10:29
    关注

    You’re passing an object through to the server side but it’s only expecting an int. Create an object with 1 property (int Amount) and use that instead of the int for your server side parameter

    评论

报告相同问题?