To call a controller action on Ajax success, you can make a separate Ajax request to the action endpoint within the success callback function of the original Ajax request.
Here's an example of how to call a controller action on Ajax success:
$.ajax({url: "https://example.com/api/data",type: "GET",success: function(response) {// Do something with the response// Call a controller action on success$.ajax({url: "/Controller/Action",type: "POST",data: { data: response },success: function(data) {// Handle the response from the controller action},error: function(xhr, status, error) {// Handle any errors from the controller action}});},error: function(xhr, status, error) {// Handle any errors from the original Ajax request}});
In this example, the original Ajax request retrieves data from a server endpoint, and the `success` callback function is called when the request is successful. Within the `success` callback function, you can perform any actions on the response data, and then call a separate controller action by making a new Ajax request to the action endpoint. The `data` parameter in the second Ajax request contains the data to be sent to the controller action.
The second Ajax request has its own `success` and `error` callback functions that handle the response from the controller action and any errors that may occur.
Note that the endpoint URL for the controller action should be defined according to the routing rules of your application. You should replace "Controller" and "Action" in the example above with the name of your controller and action methods respectively.