调用方法重临数据,Ajax学习实例3

一、WebService.asmx
  处总管务数据,在GetWhether方法中生出气候情形数据,供JqueryRequest.aspx调用,代码如下:

一、WebService.asmx

一、WebService.asmx
  管理业务数据,在GetWhether方法中发出天气情形数据,供JqueryRequest.aspx调用,代码如下:

复制代码 代码如下:

管理业务数据,在GetWhether方法中发出天气景况数据,供JqueryRequest.aspx调用,代码如下:

[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public WebService () {
//纵然利用布置的零部件,请撤销注释以下行
//InitializeComponent();
}
[WebMethod]
public string GetWhether(string cityId)
{
Random r = new Random();
int degree = r.Next(100);
string wInfo = string.Format("Today {0}'s temperature is {1} degrees", cityId, degree);
return wInfo;
}
}

[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

    public WebService () {

二、AjaxRequest.aspx
  通过点击按键来呼吁WebService.asmx的GetWhether(string cityId)方法,获取天气数据。代码如下:

public WebService () {

        //假设使用规划的零部件,请打消注释以下行
        //InitializeComponent();
    }

复制代码 代码如下:

//借使运用陈设的机件,请撤消注释以下行
//InitializeComponent();
}

    [WebMethod]
调用方法重临数据,Ajax学习实例3。    public string GetWhether(string cityId)
    {
        Random r = new Random();
        int degree = r.Next(100);

<html xmlns=";
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript" src="js/jquery-1.3.2.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" name="Text1" id="Text1"/><br />
<input type="text" name="Text2" id="Text2"/>
<br />
<input type="button" id="btn1" onclick="BtnCity_Click()"
style="width:55px; height:20px;" />
</div>
<div id="dd">
sd
</div>
<div>
<script type="text/javascript" language="javascript">
function BtnCity_Click() {
var city = $("#Text1").val();
$.ajax({
url: "WebService.asmx/GetWhether",
data: { cityId: city },
type: "post",
success: function(data, status) {
$("#dd").html("<h1>天气景况:" data.childNodes[1].text "</h1>");
}
});
}
</script>
</div>
</form>
</body>
</html>

[WebMethod]
public string GetWhether(string cityId)
{
Random r = new Random();
int degree = r.Next(100);

        string wInfo = string.Format("Today {0}'s temperature is {1} degrees", cityId, degree);
        return wInfo;
    }
}

处监护人情数据,在GetWhether方法中生出天气情状数据,供JqueryRequest.aspx调用,代码如下: 复制代码 代码如下: [System.Web.Script...

string wInfo = string.Format("Today {0}'s temperature is {1} degrees", cityId, degree);
return wInfo;
}
}

二、AjaxRequest.aspx

二、AjaxRequest.aspx

  通过点击开关来呼吁WebService.asmx的GetWhether(string cityId)方法,获取天气数据。代码如下:

由此点击按钮来呼吁Web瑟维斯.asmx的GetWhether(string cityId)方法,获取天气数据。代码如下:

<html xmlns="">
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript" src="js/jquery-1.3.2.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="text" name="Text1" id="Text1"/><br />
        <input type="text" name="Text2" id="Text2"/>
        <br />
        <input type="button" id="btn1" onclick="BtnCity_Click()"
            style="width:55px; height:20px;" />
           
    </div>
    <div id="dd">
        sd
    </div>
    <div>
        <script type="text/javascript" language="javascript">
            function BtnCity_Click() {
                var city = $("#Text1").val();
                $.ajax({
                    url: "WebService.asmx/GetWhether",
                    data: { cityId: city },
                    type: "post",
                    success: function(data, status) {
                        $("#dd").html("<h1>天气情形:" data.childNodes[1].text "</h1>");
                    }
                });
            }
        </script>
    </div>
    </form>
</body>
</html>   

<html xmlns=";
<head runat="server">
<title>bkjia.com</title>
<script type="text/javascript" language="javascript" src="js/jquery-1.3.2.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" name="Text1" id="Text1"/><br />
<input type="text" name="Text2" id="Text2"/>
<br />
<input type="button" id="btn1" onclick="BtnCity_Click()" style="width:55px; height:20px;" />
</div>
<div id="dd">
sd
</div>
<div>
<script type="text/javascript" language="javascript">
function BtnCity_Click() {
var city = $("#Text1").val();
$.ajax({
url: "WebService.asmx/GetWhether",
data: { cityId: city },
type: "post",
success: function(data, status) {
$("#dd").html("<h1>天气情形:" data.childNodes[1].text "</h1>");
}
});
}
</script>
</div>
</form>
</body>
</html>

 

处管事人务数据,在GetWhether方法中生出天气情状数据,供JqueryRequest.aspx调用,代码如下: [System.Web.Script.Services.ScriptService] p...

本文由星彩网app下载发布于前端技术,转载请注明出处:调用方法重临数据,Ajax学习实例3

TAG标签:
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。