zoukankan      html  css  js  c++  java
  • MicrosoftAjax.js 调用WebService

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    
    <script runat="server" language="C#">
        public string JsPath {
            get {
                return this.ClientScript.GetWebResourceUrl(typeof(ScriptManager), "MicrosoftMvcAjax.debug.js");
            }    
        }
    </script>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>TestWebServiceInvoke</title>
    
        <script src="http://www.cnblogs.com/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <%--    <script src="http://www.cnblogs.com/Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>--%>
        <%--<script type="text/javascript" src="<%= JsPath %>"></script>--%>
         <script src="/Services/WebService1.asmx/js" type="text/javascript"></script>
        <script type="text/javascript">
            function getInfo() {
                MvcApp1.Services.WebService1.RenderUserInfo("吴x", "123password", success);
            }
            function success(result) {
    //            var res = String.Format("Name={0},Pwd={1},Birthday={2}", result.Name, result.Password, result.Birthday);
                //            alert(res);
                alert(result.Name);
            }
        </script>
    </head>
    <body>
        <div>
        
        <input type="button" value="getInfo" onclick="getInfo()" />
        </div>
    </body>
    </html>
    //////////////////////////////////////
    
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    using MvcApp1.Models;
    
    namespace MvcApp1.Services
    {
        /// <summary>
        /// WebService1 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
        [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {
    
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
    
            [WebMethod]
            public User RenderUserInfo(string name,string password)
            {
                User u=new User();
                u.Name=name;
                u.Password=password;
                u.Birthday=DateTime.Now;
                return u;
            }
    
        }
    }
    
    
    
  • 相关阅读:
    Hystrix容错处理
    Elasticsearch基本命令
    Elasticsearch
    IDEA最新破解方式
    ElasticSearch _bulk批量处理报错The bulk request must be terminated by a newline
    Mysql引擎MyISAM和InnoDB的区别
    利用文件建立与删除swap分区
    新的分区----增加与删除swap分区
    增加,删除分区,不重启更新分区表信息
    将/home迁移到一个独立分区(新的硬盘)中
  • 原文地址:https://www.cnblogs.com/wucg/p/1841797.html
Copyright © 2011-2022 走看看