简体   繁体   English

Jquery Ajax 不将数据传递给操作方法

[英]Jquery Ajax doesn't pass data to action method

Here is my ajax method:这是我的ajax方法:

function SendMessage(contactId, e) {
        e.preventDefault();
        var content = $("#text").val();

        const dataObject = {
            contactId: contactId,
            content: content
        }

        console.log(dataObject)

        $.ajax({
            url: "/Admin/Contact/Reply",
            type: "POST",
            data: dataObject,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (res) {
                if (res != null) {
                    Swal.fire(
                        'Sent successfully!',
                        '',
                        'success'
                    )
                }
            }
        })
    }

Data comes from:数据来自:

 <form method="post">
     <input type="text" placeholder="Reply to sender"
            name="Content" required="" id="text" />
     <input type="submit" value="Send"
            onclick="SendMessage(@item.Id,event)" />
  </form>

But Ajax doesn't pass data to action method:但是 Ajax 不会将数据传递给 action 方法:

在此处输入图像描述

I am sure data is there, as it appears in console:我确信数据在那里,因为它出现在控制台中:

在此处输入图像描述

How can I send data to action method, any idea?我怎样才能将数据发送到操作方法,有什么想法吗? Thanks.谢谢。

Did you try to use default content format?您是否尝试使用默认内容格式?

Remove contentType: "application/json; charset=utf-8", to use the default value.删除contentType: "application/json; charset=utf-8",使用默认值。 The default is: application/x-www-form-urlencoded; charset=UTF-8默认是: application/x-www-form-urlencoded; charset=UTF-8 application/x-www-form-urlencoded; charset=UTF-8

If will not work try to clean a browser cache.如果不起作用,请尝试清理浏览器缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery 在 Ajax 调用 MVC 操作方法中传递数据 - jQuery to pass data in Ajax call to MVC action method 使用匿名函数时,jQuery ajax方法不传递发布数据键 - jQuery ajax method doesn't pass post data key when using anonymous function jQuery Ajax方法不将成功数据提交为数组 - JQuery Ajax Method doesn't submit success data as an Array 如何将数据从下拉列表传递到操作方法以使用帖子 jquery ajax 调用保存数据 - How to pass data from dropdown list to action method to save data using post jquery ajax call 帮助使用jquery .ajax()方法将聚合数据传递给mvc2操作 - help using jquery .ajax() method to pass aggregate data to mvc2 action 使用jQuery ajax显示输出后,使用PHP post方法不会传递值 - After showing output using jQuery ajax the value doesn't pass using PHP post method jQuery Ajax Get不会将接收到的数据传递给Internet Explorer的成功函数 - jQuery Ajax Get Doesn't Pass Received Data Into Success Function at Internet Explorer jQuery单击操作不适用于Ajax附加的动态内容 - Jquery click action doesn't work to ajax appended dynamic content jQuery ajax调用mvc Action不会触发成功/错误 - jQuery ajax call to mvc Action doesn't fire success/error MVC操作不会被jquery ajax调用击中 - MVC action doesn't get hit by a jquery ajax call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM