Articles → ANGULAR.JS → Call controller's action method using $http angular.js

Call controller's action method using $http angular.js






Syntax


$http({
    url: "Controller/Action Method",
    method: "GET/Post",
    params: List of parameters.
});





Create a controller method




public string Index1(string name) {
    return string.Format("Hello {0}", name);
}





Call $http from index.cshtml page




<script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> 
<script type = "text/javascript">
    var app = angular.module('app', []);
    app.controller('myController', function($scope, $http) {
    var response = $http({
         url: "Home/Index1",
         method: "GET",
         params: {
             name: "gyan"
         }
     });
     response.success(function(data, status, headers, config) {
         alert(data);

     }).error(function(data, status, headers, config) {
         alert("failure");
     });
 }); 
</script>



Output




Picture showing calling controller's action method using $http angular.js

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, July 28, 2015

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250