352229 (9) [Avatar] Offline

I am using angular.js $http in asp.net application.

C# code
    public static string GetCountry()
        List<string> list = new List<string>();
        using (SqlConnection connection = new SqlConnection(@"Conn_String"))
            using (SqlCommand command = new SqlCommand("select top 2 Title from Task", connection))
                using (SqlDataReader reader = command.ExecuteReader())
                    while (reader.Read())
        // Serialize the results as JSON
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(list.GetType());
        MemoryStream memoryStream = new MemoryStream();
        serializer.WriteObject(memoryStream, list);

        // Return the results serialized as JSON
        string json = Encoding.Default.GetString(memoryStream.ToArray());
        return json;

And in aspx page I am using following code

<head id="Head1" runat="server">
    <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 request = $http({
                method: "GET",
                url: "Default2.aspx/GetCountry",

            request.success(function (response) {

            request.error(function () {
                alert("Error in loading contents");
    <form id="form1" runat="server">
    <div ng-app="app" ng-controller="myController">

But I am not able to call $http. Is there anything I am missing
Lukas Ruebbelke (107) [Avatar] Offline
The structure of your $http call is wrong. It should follow this pattern.

// Simple GET request example :
  success(function(data, status, headers, config) {
    // this callback will be called asynchronously
    // when the response is available
  error(function(data, status, headers, config) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.

Let me know if you would like to me elaborate further.
352229 (9) [Avatar] Offline
Hi Lukas

Thanks for the reply. Now I am getting success, but $http is not calling the server side code.