Answers for "Call Controller Method from View using jQuery AJAX"

0

Call Controller Method from View using jQuery AJAX

// Credits to: https://www.aspsnippets.com/Articles/ASPNet-MVC-Call-Controller-Method-from-View-using-jQuery-AJAX.aspx

$.ajax({
    type: "POST",
    url: "/Home/AjaxMethod",
    data: '{name: "' + $("#txtName").val() + '" }',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (response) {
        alert("Hello: " + response.Name + " .\nCurrent Date and Time: " + response.DateTime);
    },
    failure: function (response) {
        alert(response.responseText);
    },
    error: function (response) {
        alert(response.responseText);
    }
});
Posted by: Guest on September-23-2021

Code answers related to "Call Controller Method from View using jQuery AJAX"

Code answers related to "Javascript"

Browse Popular Code Answers by Language