1

Ajax doesnt seem to be working on my View. I simplified my problem down to having a button call a controller method via ajax. The result is the same html of the view is being appended to the div. Looking through the debugger, the same GetEventForm url is called and not TestAjax

Button in GetEventForm.cshtml

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

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

Ajax

<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>

Controller

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

Before Click

After Click

1 Answer 1

1

Try lowercase "url":

$.ajax({...

    url : '...'

    });
Sign up to request clarification or add additional context in comments.

1 Comment

This is obviously the answer. It's just one of those days. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.