Ajax C # mvc call sends both message and get

I considered several solutions for creating an ajax call and did not mention this problem anywhere, I feel that it may be something specific to the environment with which I work. My controller:

    [HttpPost]
    public ActionResult ChangeDefualtCC(string a)
    {

        return Json("ok");
    }
    [HttpGet]
    public ActionResult ChangeDefualtCC()
    {

        return Json("ok");
    }

JS:

    $("nevermind").change(function () {

    $.ajax({
        type: "POST",
        url: "/Account/ChangeDefualtCC",
        dataType: "json",
        data: {
            a: "A"
        },
        success: function (data) { console.log(data)},
        error: function (data) { console.log("error");}
    });
});

Controller code never gets in, and this is what I see in chrome after ajax call:

EDIT 2: The page falls into the [HttpGet] method.

chrome network tab

EDIT: I also noted Ektron because it is used in the project, and it is possible that this affects the call.

My routes: mvc routes

Update . I tried using Get as well as Post, and also returning to the view I was in, I get 302 every time.

any ideas?

+4
source share
3

CMS Ektron. , Ektron # URL- URL-.

0

, "get", . , ajax, .

$.ajax({
        type: "POST",
        url: "/Account/ChangeDefualtCC",
        contentType: 'application/json; charset=utf-8',       
        dataType: "json",
        data: {
            a: "A"
        },
        success: function (data) { console.log(data)},
        error: function (data) { console.log("error");}
    });
0

Your code seems absolutely correct. This is not an exact solution, but try, maybe it will work.

 $("nevermind").change(function () {

     $.post("/../Home/ChangeDefualtCC", { a: "A" }, function (data) {

        console.log(data)
     });
});
0
source

Source: https://habr.com/ru/post/1523402/


All Articles