How do you call controller action in Ajax success

To call a controller action in Ajax success, you can use the `$.ajax()` function in jQuery to make an asynchronous HTTP (Ajax) request to the server, and in the `success` callback function, you can call the controller action.

Here is an example:

$.ajax({
    type: "POST",
    url: "/Controller/Action",
    data: {
        // data to be sent to the server, if any
    },
    success: function (data) {
        // code to be executed if the request succeeds
        // call the controller action here, passing any required parameters
        $.ajax({
            type: "POST",
            url: "/Controller/Action2",
            data: {
                // data to be sent to the server, if any
            },
            success: function (data) {
                // code to be executed if the request succeeds
            },
            error: function (xhr, status, error) {
                // code to be executed if the request fails
            }
        });
    },
    error: function (xhr, status, error) {
        // code to be executed if the request fails
    }

});

In this example, the `$.ajax()` function makes a POST request to the first controller action at `/Controller/Action`. If the request succeeds, the `success` callback function is called, and within that function, another `$.ajax()` function is used to make a POST request to the second controller action at `/Controller/Action2`. If the second request also succeeds, the `success` callback function for the second request is executed.

Previous Post Next Post