【问题标题】:ASP.NET Ajax doesnt call UrlASP.NET Ajax 不调用 Url
【发布时间】:2016-12-15 21:31:35
【问题描述】:

Ajax 似乎没有在我的视图上工作。我将问题简化为让按钮通过 ajax 调用控制器方法。结果是将视图的相同 html 附加到 div。查看调试器,调用了相同的 GetEventForm url,而不是 TestAjax

GetEventForm.cshtml 中的按钮

<input type="button" id="btn" value="Test Ajax" class="btn-sm"/>

<div id="rule"> </div>

阿贾克斯

<script type="text/javascript">
    $(document).ready(function () {
        $('#btn').on('click', function() {
            $.ajax({
                type: 'GET',
                cache: false,
                Url: '@Url.Action("TestAjax","Events")',
                success: function(result) { $("#rule").html(result); }
            });
        });
     });
 </script>

控制器

    public string TestAjax()
    {
        return "Response string from Controller!";
    }

Before Click

After Click

【问题讨论】:

    标签: javascript jquery html asp.net ajax


    【解决方案1】:

    试试小写的“url”:

    $.ajax({...

        url : '...'
    
        });
    

    【讨论】:

    • 这显然是答案。这只是那些日子之一。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 2018-09-26
    • 2013-05-13
    • 1970-01-01
    • 2017-06-10
    相关资源
    最近更新 更多