Error: 404 status code when POST Ajax in Asp.Net Core

Dung Do Tien Mar 16 2021 356

I have a project using Asp.Net Core. With a Login form when filling in all information and click Submit button I call ajax to submit the form as below:

$(document).ready(function () {
    //login function
    $("#btnLogin").click(function () {
        login.submit();
    });
});

//object that contains details required to login/ validation
var login = {
    submit: function () {
        var email = $("#txtEmail").val();
        var pass = $("#txtPass").val();
        var isRemember = $("#cboRemember").is(":checked");
        $.ajax({
            type: "POST",
            dataType: "JSON",
            url: "/home/login",
            data: { Email: email, Password: pass, IsRemember: isRemember },
            success: function (res) {
                if (res.success) {
                    window.location.href = res.linkDirect;
                } else {
                    $(".message-error").html(res.message);
                }
            }
        });
    }
}

I work fine for me when test in window local but when I publish into the IIS server and Azure but I got an error 404 status as the image below:

Error: 404 status code when POST Ajax in Asp.Net Core

Thanks for any suggestions.

Have 1 answer(s) found.
  • J

    Jair Rojas Garcia Mar 16 2021

    I got the same error.

    I only need to convert data parameters from object to string JSON. It worked for me.

    You can use JSON.stringify() method to convert. You can see as below:

    $.ajax({
        type: "POST",
        dataType: "JSON",
        url: "/home/login",
        data: JSON.stringify({ Email: email, Password: pass, IsRemember: isRemember }),
        success: function (res) {
            ////
        }
    });

    I hope it works for you.

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close