如何使用asp.net webforms中的angularJs从sqlserver数据库获取数据使用webmethods [英] How to fetch data from sqlserver database using angularJs in asp.net webforms usingwebmethods

查看:97
本文介绍了如何使用asp.net webforms中的angularJs从sqlserver数据库获取数据使用webmethods的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是html代码

This is the html code

<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>





这是webService代码



This is the webService Code

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;
    }
    
}

推荐答案

范围,


http){
var url = WebService.asmx / GetUserDetails;
http) { var url = "WebService.asmx/GetUserDetails";


http.get(url)
.success( function (数据){
alert( success);
var myjson = JSON .parse(data);
http.get(url) .success(function (data) { alert("success"); var myjson = JSON.parse(data);


这篇关于如何使用asp.net webforms中的angularJs从sqlserver数据库获取数据使用webmethods的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆