• asp.net ajax调用webservice


    WebService代码

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Web;
    using System.Web.Services;
    using System.Web.Services.Protocols;
    using System.Web.Script.Services;
    
    namespace AJAXEnabledWebApplication1
    {
        /// <summary>
        /// WebService 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [ToolboxItem(false)]
        [ScriptService]
        public class WebService : System.Web.Services.WebService
        {
    
            [WebMethod]
            public string HelloWorld(string str)
            {
                return "Hello " + str;
            }
    
        }
    }

    页面代码:

    <%@ Page Language="C#" MasterPageFile="~/Manager/MasterPage/PageTemplate.Master" AutoEventWireup="true" CodeBehind="Test222.aspx.cs" Inherits="AJAXEnabledWebApplication1.Test222" Title="无标题页" %>
    
    <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI" TagPrefix="asp" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="PageBody" runat="server">
        <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
            <Services>
                <asp:ServiceReference Path="WebService.asmx"/>
            </Services>
        </asp:ScriptManagerProxy>
        <script type="text/javascript">
        function test()
        {
            AJAXEnabledWebApplication1.WebService.HelloWorld("胡晓伟",succeeded,failed);
        }
        
        function succeeded(result)
        {
            alert(result);
        }
        
        function failed(error)
        {
            alert("系统出现故障!请手动保存好页面!");
        }
        </script>
        
            <div>
            <input id="Button1" type="button" value="button" onclick="test();" />
        </div>
    </asp:Content>
  • 相关阅读:
    纯线性同余随机数生成器
    读书笔记之:C语言参考手册(第5版)
    读书笔记之:C语言函数库
    读书笔记之:C/C++程序员实用大全—C/C++最佳编程指南
    C++中重要关键字总结
    读书笔记之:C++参考大全
    读书笔记之:C++大学教程(第2版)
    C语言中函数参数入栈的顺序
    ANSI设备驱动器
    可以输出自己的源程序代码(quine)
  • 原文地址:https://www.cnblogs.com/CoderWayne/p/4485643.html
Copyright © 2020-2023  润新知