[英]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.