zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    ServU使用方法及应用技巧
    Mozilla公布火狐4详情:更快 更支持开放标准
    FastReport4.6程序员手册_翻译 转
    Delphi调用C写的dll
    动态创建Fastreport
    字符串通用类
    去除全角半角字符
    系统运行的命令集锦
    打印机的大小设置
    旋转字体的设置
  • 原文地址:https://www.cnblogs.com/CoderWayne/p/4485643.html
Copyright © 2011-2022 走看看