skip to Main Content

I saw lot of post regarding this, but i don’t seem to find the answer,
I am trying to call controller Get method though AJAX

JS

 $(document).ready(function () {
 $.ajax({
                type: "GET",
                url: "api/CookBooks/",
                dataType: "xml",
                success: function (data) {
                    $.each(data, function (key, val) {
                        debugger;
                    });
                },
                error: function (xhr, textStatus, errorThrown) {
                    debugger;
                }
            });
        });

Controller

[HttpGet]
public static IEnumerable<DTO> GetLatest()
{
// ...
}

i am getting response error "he requested resource does not support http method ‘GET’"
Why is that?

2

Answers


  1. Do you have other HttpGet method inside controller?

    Login or Signup to reply.
  2. you can call your controller Get method like below

    $.ajax({
            url: "controllerName/MethodName",
            type: 'GET',
            dataType: 'json', // added data type
            success: function(data) {
                $.each(data, function (key, val) {
                        debugger;
                    });
            }
        });
    

    Make sure you have proper names of controller method and that names you used in this ajax call,

    along with that, if you have apis then only you have to add api as prefix, but if your project is mvc type then no need of appending api prefix

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search