Amaan Khan Amaan Khan - 1 year ago 270
AngularJS Question

Get Json Data From Asp.Net Webmethod and Consume in angularJS

Can any one guide me how to get json data from webmethod, and consume it in angularJS.

app.controller('MainController', ['$scope', function ($scope, $http) {
try {
$http({ method: 'GET', url: 'ProblemList.aspx/GetProblemList' })
.success(function (data, status, headers, config) {
alert(data); }).error(function (data, status, headers, config) {
} catch (e) {
throw e;

Answer Source

I had the same issue, I tried many different ways, this is the way I found it works... ( I think the tricks is a combination of the header config, and the json parameter with "data : {}", I am not sure but It was really tricky )

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestAngular.aspx.cs" Inherits="COEWebApp.NCoe.Employees.TestAngular" %>

<!DOCTYPE html>
<html lang="en">

    <script src=""></script>

<body ng-app="myapp">

  <div ng-controller="MyController" >
    <button ng-click="myData.doClick(item, $event)">Send AJAX Request</button>
    Data from server: {{myData.fromServer}}

      angular.module("myapp", [])
          .controller("MyController", function ($scope, $http) {
              $scope.myData = {};
              $scope.myData.doClick = function (item, event) {

                  $'TestAngular.aspx/GetEmployees', { data: {} })
                    .success(function (data, status, headers, config) {
                        $scope.myData.fromServer = data.d;
                    .error(function (data, status, headers, config) {
                        $scope.status = status;


          }).config(function ($httpProvider) {

              $ = {};

              $["Content-Type"] = "application/json; charset=utf-8";




And on the same aspx page on the codebehid this is the simple code...

public static string GetEmployees()
  return "OK-test";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download