Click here to Skip to main content
15,900,418 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more: , +
This is the html code
HTML
<form>
       <div ng-app="myApp" ng-controller="questionsController">
           search:<input type="text" ng-model="search" />
           <table>
               <tr ng-repeat="i in questions | filter:search">
                   <td>{{i.PatientId}}
                   </td>
                   <td>{{i.PatientName}}
                   </td>
               </tr>
           </table>
       </div>

<script>
    var app = angular.module('myApp', []);
    app.controller('questionsController', function ($scope, $http) {
        var url = "WebService.asmx/GetUserDetails";
        $http.get(url)
                   .success(function (data) {
                       alert("success");
                       var myjson = JSON.parse(data);

                       $scope.questions = JSON.parse(myjson);
                   })
                   .error(function (data) {
                       alert("error");
                       alert(data);
                   })
    })
   </script>
   </form>


This is the webService Code
C#
public class WebService : System.Web.Services.WebService {
    public static HospitalEntities _entities = new HospitalEntities();
    public WebService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public string HelloWorld() {
        return "Hello World";
    }

    [WebMethod]
    public static string GetUserDetails()
    {
        var data = _entities.PatientReg.ToList();

        var jsondata = new JavaScriptSerializer().Serialize(data);

        return jsondata;
    }
    
}
Posted
Comments
Sinisa Hajnal 24-Aug-15 2:23am    
What is the question/problem?
eng.ahmedfathy 26-Aug-15 5:00am    
the "data" object returend in the success function is not Json it is the innerhtml of the page
Sinisa Hajnal 26-Aug-15 7:09am    
Put a breakpoint on var data = line and check each value separately. Find out which doesn't work as you expect it to.

Consider returning JsonResult or IHhtpActionResult instead of string.

Finally, consider using Newtonsoft.Json library instead of default serializer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900