The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

352229 (9) [Avatar] Offline

I am using angular.js $http in 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=""></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.