Monday, 12 January 2015

Jquery Ajax call not working in MVC, after doployed into IIS 7

JQuery Ajax method call not working in IIS 7 +



    $.ajax({
            cache: false,
            type: "GET",
            url: "/Base/GetCities/",
            data: { "id": _Id },
            success: function (data) {

            },
            error: function (xhr, ajaxOptions, thrownError) {

            }
        });


 This is normal Issue While Dealing with Url's in ASP.Net MVC. We need to Consider the Following things.

1. We never use the hardCoded Url's in Asp.Net MVC,
2. Allways Use Url helpers While dealing with Url's in Asp.Net MVC.

We need to Write Url's in Url helpers to generate it.


url: '@Url.Action("GetCities", "Base")'


 
For Example The Code like this

   $.ajax({

            cache: false,
            type: "GET",           
            url: '@Url.Action("GetCities", "Base")',
            data: { "id": _Id },
            success: function (data) {

            },
            error: function (xhr, ajaxOptions, thrownError) {

            }
        });


No comments:

Post a Comment