Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Calling MVC controller from Javascript ajax

<head runat="server">
    <title>FirstAjax</title>
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var serviceURL = '/AjaxTest/FirstAjax';

            $.ajax({
                type: "POST",
                url: serviceURL,
                data: param = "",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: successFunc,
                error: errorFunc
            });

            function successFunc(data, status) {     
                alert(data);
            }

            function errorFunc() {
                alert('error');
            }
        });
    </script>
</head>
Comment

Calling MVC controller from Javascript ajax

public class AjaxTestController : Controller
{
    //
    // GET: /AjaxTest/
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult FirstAjax()
    {
        return Json("chamara", JsonRequestBehavior.AllowGet);
    }   
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: copy to clipboard angular 
Javascript :: react is there a safe area view for android 
Javascript :: how to change color of font in js 
Javascript :: regex for check if string is only empty or whitespace javascript 
Javascript :: how to find lcm in javascript 
Javascript :: Use History React Router v5 app 
Javascript :: access to static file nodejs 
Javascript :: javascript get placeholder value 
Javascript :: javascript syntax for check null or undefined or empty 
Javascript :: javascript class constructor 
Javascript :: javascrpt formatBytes 
Javascript :: jquery event keycode 
Javascript :: find the largest number in array javascript 
Javascript :: vue watch child property 
Javascript :: cypress ignore error 
Javascript :: discord delete messag 
Javascript :: Select options of Select2 control based on values using Jquery 
Javascript :: on mouse not over jquiery 
Javascript :: remove property from object js 
Javascript :: javascript capitalize array 
Javascript :: how to render a new page in node js through express 
Javascript :: javascript squared 
Javascript :: Javascript how to compare three numbers 
Javascript :: reverse every word 
Javascript :: for each jquery 
Javascript :: today date javascript 
Javascript :: how to use url parameters in react 
Javascript :: addclass to elementref angular 
Javascript :: get value of ajax success in variable 
Javascript :: javascript string search second occurrence 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =