簡體   English   中英

MVC5的jQuery post方法

[英]jquery post method with MVC5

<script type="text/javascript">
    $(".categories").click(function () {
        console.log("pre post");
        $.post('Index/Home/' + $(this).attr('data-id'), function (data) {
            console.log("category post success");
        });
    });
</script>

誰能告訴我這個代碼片段有什么問題嗎? :-/

我的路線完美。

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index"}
        );
    }

您發布的網址有誤。 您在控制器名稱之前寫了動作名稱,它應該是Home / Index,如下所示:

 $(".categories").click(function () {
            console.log("pre post");
            $.post('Home/Index/' + $(this).attr('data-id'), function (data) {
                console.log("category post success");
            });
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM