ajax调用webservice



前台:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="AdmanageSystem.WebForm1" %>


<!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></title>
    <script src="http://localhost:15061/Scripts/jquery-1.8.js" type="text/javascript"></script>


    <script type="text/javascript">
        function clickMe() {
            document.getElementById("lb2").innerText = "Hello world";
            document.getElementById("lb3").innerText = "Hello world3";
            return;
        }


        function myClick() {


            $.ajax({
                type: "post",
                url: "WebForm1.aspx/takeCellCode",


                //data: "{'cellPhoneNum':'" + cell.value + "','userName':'" + userName.value + "','ipAddress':'" + ipAddress.value + "'}",


                data: "{'cellPhoneNum':'13254682354','userName':'test','ipAddress':'127.0.0.1'}",


                //data: "cellPhoneNum=13254682354&userName=test&ipAddress=127.0.0.1",


                contentType: "application/json; charset=utf-8",
                dataType: "json",


                success: function (data) {
                    //                    $("#bindCellTempValidateCode").val(data.d[0]);


                    //                    curCountForBindCell = countForBindCell;
                    //                    $("#takeCellForBindCellBtn").attr("disabled", "true");
                    //                    $("#takeCellForBindCellBtn").val("请在" + curCountForBindCell + "秒内输入");
                    //                    InterValObjForBindCell = window.setInterval(SetRemainTimeForBindCell, 1000);
                    //                    myClick(cell.value, data.d[0]);


                    //alert(data.d);


                    //alert(data.d[0]);
                    //alert(data.d[1]);
                    //alert(data.d[2]);




                    $.each(data, function (k, v) {
                        alert(k);
                        alert(v);
                    });


                },
                error: function (err) {
                    alert(err);


                }
            });


        }




    </script>


</head>
<body>
    <form id="form1" runat="server">
    <div>
    
<%-- 不使用label,使用span或服务器端label控件   <label id="lb1">我是原来的</label>--%>


    <asp:label id="lb2" runat="server" Text="我是原来的"></asp:label>
    <span id="lb3">我是原来的1</span>
    <span id="Span1">我是原来的2</span>
    <span id="Span2">我是原来的3</span>
    <span id="Span3">我是原来的4</span>
    <span id="Span4">我是原来的5</span>
    <span id="Span5">我是原来的6</span>
  
    <input type="button" οnclick="clickMe()" value="我是按钮,按我一下" />




      <input type="button" οnclick="myClick()" value="我是ajax方法" />




    </div>
    </form>
</body>
</html>



后台:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;


namespace AdmanageSystem
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


        }




        //获取手机验证码
        [WebMethod]
        public static List<string> takeCellCode(string cellPhoneNum, string userName, string ipAddress)
        //public static string takeCellCode(string cellPhoneNum, string userName, string ipAddress)
        {
            try
            {
                List<string> list = new List<string>();


                //TODO:手机验证码
                string code = (new Random()).Next(1000, 9999).ToString();


                list.Add(cellPhoneNum+",");
                list.Add(userName + ",");
                list.Add(ipAddress + ",");


                return list;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }








    }
}










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值