Question

I'm deploying an asp.net mvc 4 website to IIS 8 in localhost (Windows 8.1 x64).It works fine in visual studio 2012 on debug mode, but when I deploy to IIS 8 the ajax request doesn't work at all, I get a 404 error for the request.By the way, I can CRUD to database anything the while is not a json request. Any suggestion ???!!!

This is my javascript code:

@section scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            $(".visibility").click(function () {
                var visibility = $(".visibility").attr("checked");
                var visibilityBool;
                if (visibility == "checked")
                    visibilityBool = true;
                else
                    visibilityBool = false;
                $.ajax({
                    url: "/Questionnaire/ChangeVisibility",
                    type: "GET",
                    data: {
                        "id": $(".questionnaire > h3").attr("data-id"),
                        "visibility": visibilityBool
                    },
                    success: function (data) {
                    }
                });
            });

        });
    </script>
}
Was it helpful?

Solution

Instead of hard-coding the url, try UrlHelper.Action:

url: '@Url.Action("ChangeVisibility", "Questionnaire")'

A couple other things..

Instead of $(".visibility").attr("checked"), use this.checked. The attribute's value doesn't change when the user checks the checkbox.

Also, this should probably be a post request, not a get. If it has to be a get for some reason, use the ajax option cache: false.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top