日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

Microsoft Asp.Net Ajax框架入门(12) 了解异步通信层

發(fā)布時間:2023/12/31 asp.net 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Microsoft Asp.Net Ajax框架入门(12) 了解异步通信层 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
VS 2008

本文通過兩個簡單的例子,了解Asp.Net Ajax Asynchronous Communication Layer

Asp.Net Ajax異步通信層提供了一系列客戶端的類,用于客戶端請求服務(wù)端

第一個例子:請求服務(wù)端頁面
1) 被請求頁 Ajax_GetUserName.aspx

????html代碼僅留頁面聲明,其余全部清楚:
<%@?Page?Language="C#"?AutoEventWireup="true"?CodeFile="Ajax_GetUserName.aspx.cs"?Inherits="Ajax_GetUserName"?%>
????Ajax_GetUserName.aspx.cs頁面寫處理邏輯:
public?partial?class?Ajax_GetUserName?:?System.Web.UI.Page
{
????
protected?void?Page_Load(object?sender,?EventArgs?e)
????
{
????????
if?(Request.QueryString["userId"]?==?"1")?{
????????????Response.Write(
"guozhijian");
????????}

????????
else?{
????????????Response.Write(
string.Empty);
????????}

????}

}

2) 客戶端請求

<%@?Page?Language="C#"?AutoEventWireup="true"??CodeFile="Default.aspx.cs"?Inherits="_Default"?%>

<!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>Untitled?Page</title>
????
<script?type="text/javascript">
????????function?btnGetNameClickHandler()?
{
????????????var?req?
=?new?Sys.Net.WebRequest();
????????????req.set_url(
"Ajax_GetUserName.aspx?userId=1");
????????????req.add_completed(requestCompleted);
????????????req.invoke();
????????}

????????function?requestCompleted(executor,?eventArgs)?
{
????????????
if(executor.get_statusCode()?==?200)?{
????????????????alert(executor.get_responseData());
????????????}

????????}

????
</script>
</head>
<body>
????
<form?id="form1"?runat="server">
????
<asp:ScriptManager?ID="smgr"?runat="server"></asp:ScriptManager>
????
<div>
????????
<input?type="button"?id="btnGetName"?onclick="btnGetNameClickHandler()"?value="get?name"?/>
????
</div>
????
</form>
</body>
</html>
第二個例子:請求XML文檔
1)新建UserInfos.xml

<?xml?version="1.0"?encoding="utf-8"??>
<userInfos>
??
<userInfo>
????
<userId>1</userId>
????
<userName>guozhijian</userName>
??
</userInfo>
??
<userInfo>
????
<userId>2</userId>
????
<userName>zhenglanzhen</userName>
??
</userInfo>
</userInfos>
2)客戶端請求

function?btnGetXmlClickHandler()?{
????????????var?req?
=?new?Sys.Net.WebRequest();
????????????req.set_url(
"UserInfos.xml");
????????????req.add_completed(getXmlCompleted);
????????????req.invoke();????
????????}

????????function?getXmlCompleted(executor,?eventArgs)?
{
????????????
if(executor.get_statusCode()?==?200)?{
????????????????alert(executor.get_xml().xml);
????????????}

????????}

轉(zhuǎn)載于:https://www.cnblogs.com/guozhijian/archive/2008/02/17/1071469.html

總結(jié)

以上是生活随笔為你收集整理的Microsoft Asp.Net Ajax框架入门(12) 了解异步通信层的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。