gpt4 book ai didi

javascript - 在 Ajax 中调用 Controller 函数

转载 作者:行者123 更新时间:2023-12-02 17:54:46 24 4
gpt4 key购买 nike

我想用 ajax 调用这个黄色 Controller 函数 ( Image of my project )。这是我在 View 中的 JavaScript 函数:

function notificationDivPressed(element,x,user,numberOfUsers) {  

jQuery(document).ready(function ($) {

$.ajax({
url: 'MvcApplication3/Controllers/NotificationController/ChangeReadStatus',
type: "POST",
cache: false,
data: { arg: x },
success: function (data) {

}
}
});
});
}

当我这样写 url 时(url: 'MvcApplication3/Controllers/NotificationController/ChangeReadStatus'),它不起作用。我应该改变什么才能得到想要的结果?

最佳答案

正如您所见,您的 URL 是错误的(因为您只是使用了项目路径和类名的混合,而不是 MVC 框架将重写并路由到正确方法的正确 URL)。

更改为:

url: '@Url.Action("ChangeReadStatus", "Notification")'

关于javascript - 在 Ajax 中调用 Controller 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21045749/

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