calling mvc controller from javascript ajax

Solutions on MaxInterview for calling mvc controller from javascript ajax by the best coders in the world

showing results for - "calling mvc controller from javascript ajax"
Mía
30 Nov 2018
1<head runat="server">
2    <title>FirstAjax</title>
3    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
4    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
5    <script type="text/javascript">
6        $(document).ready(function () {
7            var serviceURL = '/AjaxTest/FirstAjax';
8
9            $.ajax({
10                type: "POST",
11                url: serviceURL,
12                data: param = "",
13                contentType: "application/json; charset=utf-8",
14                dataType: "json",
15                success: successFunc,
16                error: errorFunc
17            });
18
19            function successFunc(data, status) {     
20                alert(data);
21            }
22
23            function errorFunc() {
24                alert('error');
25            }
26        });
27    </script>
28</head>
29
Agustina
28 Feb 2018
1public class AjaxTestController : Controller
2{
3    //
4    // GET: /AjaxTest/
5    public ActionResult Index()
6    {
7        return View();
8    }
9
10    public ActionResult FirstAjax()
11    {
12        return Json("chamara", JsonRequestBehavior.AllowGet);
13    }   
14}
15