gpt4 book ai didi

jquery - ASP MVC 3 HTTP Post 通过 JQuery 不断返回 500。Url 和 Controller 匹配

转载 作者:行者123 更新时间:2023-12-01 06:06:19 24 4
gpt4 key购买 nike

我有一个操作链接,我想将其发送到我的 Controller ,但是我不断收到 HTTP 500。

这是我的 jQuery

<script type="text/javascript">    $(document).ready(function () {        $('.thing').click(function (e) {            e.preventDefault();            $.ajax({                url: this.href,                dataType: "json",                type: "POST",                success: function (data) {                    if (data.Success == true) {                       // do something                    }                    else {                        alert(data.Message);                    }                },                error: function (textStatus, errorThrown) {                    // request always errors                }            });        });    });    </script>

和我的操作链接代码

@Html.ActionLink("my link", "DoStuff", "Dude", new { thingId = item.Id }, new { @class = "thing" })

我的 Controller

public class DudeController : Controller{    [HttpPost]    public ActionResult DoStuff(int thingId)    {        return Json(new { Success = true, Message = string.Empty }, JsonRequestBehavior.AllowGet);    }}

有什么想法吗?

最佳答案

您可以尝试从ajax调用中删除dateType并添加数据吗?对我来说它有效:

$(document).ready(function () {
$('.thing').click(function (e) {
e.preventDefault();
$.ajax({
url: this.href,
type: "POST",
data: this.thingId,
success: function (data) {
if (data.Success == true) {
// do something
alert(data.Message);
}
else {
alert(data.Message);
}
},
error: function (textStatus, errorThrown) {
// request always errors
}
});
});
});

关于jquery - ASP MVC 3 HTTP Post 通过 JQuery 不断返回 500。Url 和 Controller 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5695772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com