免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
輕松掌握XMLHttpRequest對(duì)象

輕松掌握XMLHttpRequest對(duì)象

XmlHttp是什么?

      最通用的定義為:XmlHttp是一套可以在Javascript、VbScript、Jscript等腳本語(yǔ)言中通過http協(xié)議傳送或從接收XML及其他數(shù)據(jù)的一套API。XmlHttp最大的用處是可以更新網(wǎng)頁(yè)的部分內(nèi)容而不需要刷新整個(gè)頁(yè)面。

來自MSDN的解釋:XmlHttp提供客戶端同http服務(wù)器通訊的協(xié)議??蛻舳丝梢酝ㄟ^XmlHttp對(duì)象(MSXML2.XMLHTTP.3.0)向http服務(wù)器發(fā)送請(qǐng)求并使用微軟XML文檔對(duì)象模型Microsoft? XML Document Object Model (DOM)處理回應(yīng)。 現(xiàn)在的絕對(duì)多數(shù)瀏覽器都增加了對(duì)XmlHttp的支持,IE中使用ActiveXObject方式創(chuàng)建XmlHttp對(duì)象,其他瀏覽器如:Firefox、Opera等通過window.XMLHttpRequest來創(chuàng)建xmlhttp對(duì)象。

XmlHttp對(duì)象的屬性:


XmlHttp對(duì)象的方法:


如何發(fā)送一個(gè)簡(jiǎn)單的請(qǐng)求?
      最簡(jiǎn)單的請(qǐng)求是,不以查詢參數(shù)或提交表單的方式向服務(wù)器發(fā)送任何信息.使用XmlHttpRequest對(duì)象發(fā)送請(qǐng)求的基本步驟:
      ● 為得到XmlHttpRequest對(duì)象實(shí)例的一個(gè)引用,可以創(chuàng)建一個(gè)新的XmlHttpRequest的實(shí)例。
      ● 告訴XmlHttpRequest對(duì)象,那個(gè)函數(shù)回處理XmlHttpRequest對(duì)象的狀態(tài)的改變.為此要把對(duì)象的
         onreadystatechange屬性設(shè)置為指向JavaScript的指針.
      ● 指定請(qǐng)求屬性.XmlHttpRequest對(duì)象的Open()方法會(huì)指定將發(fā)送的請(qǐng)求.
      ● 將請(qǐng)求發(fā)送給服務(wù)器.XmlHttpRequest對(duì)象的send()方法將請(qǐng)求發(fā)送到目標(biāo)資源.

XmlHttpRequest實(shí)例分析
      我想大家都知道,要想使用一不對(duì)象首先我門得做什么?是不是必須先創(chuàng)建一個(gè)對(duì)象吧.比如C#和Java里用new來實(shí)例對(duì)象.那么我門現(xiàn)在要使用XmlHttp對(duì)象是不是也應(yīng)該先創(chuàng)建一個(gè)XmlHttp對(duì)象呢?這是毫無疑問的!那么下面我們來看看在客戶端怎么創(chuàng)建一個(gè)XmlHttp對(duì)象,并使用這個(gè)對(duì)象向服務(wù)端發(fā)送Http請(qǐng)求,然后處理服務(wù)器返回的響應(yīng)信息.

1.創(chuàng)建一個(gè)XmlHttp對(duì)象(在這里我以一個(gè)無刷新做加法運(yùn)算的實(shí)例 )

 1
var xmlHttp;
 2
function createXMLHttpRequest()
 3
{
 4
   if(window.ActiveXObject)
 5
   {
 6
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 7
   }
 8
   else if(window.XMLHttpRequest)
 9
   {
10
      xmlHttp = new XMLHttpRequest();
11
   }
12
}

2.定義發(fā)送請(qǐng)求的方法

1
//處理方法
2
function AddNumber()
3
{
4
  createXMLHttpRequest();
5
  var url= "AddHandler.ashx?num1="+document.getElementById("num1").value+"&num2="+document.getElementById("num2").value;
6
  xmlHttp.open("GET",url,true);
7
  xmlHttp.onreadystatechange=ShowResult;
8
  xmlHttp.send(null);
9
}

3.定義回調(diào)函數(shù),用于處理服務(wù)端返回的信息

 1
//回調(diào)方法
 2
function ShowResult()
 3
{
 4
   if(xmlHttp.readyState==4)
 5
   {
 6
      if(xmlHttp.status==200)
 7
      {
 8
          document.getElementById("sum").value=xmlHttp.responseText;
 9
      }
10
   }
11
}
      在上面這個(gè)實(shí)例中,是在客戶端想服務(wù)端的AddHandler.ashx發(fā)送的請(qǐng)求,并傳遞兩個(gè)參數(shù)(也就是待相加的數(shù))過去,下面我門來看看服務(wù)端是怎么處理接收傳遞過去的兩個(gè)參數(shù)以及怎么實(shí)現(xiàn)加法運(yùn)算并返回結(jié)果到客戶端的.代碼如下:
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;

public class Handler : IHttpHandler 
{
    
    public void ProcessRequest (HttpContext context) 
    {
        context.Response.ContentType = "text/plain";
        int a = Convert.ToInt32(context.Request.QueryString["num1"]);
        int b = Convert.ToInt32(context.Request.QueryString["num2"]);
        int result = a + b;
        context.Response.Write(result);
    }
 
    public bool IsReusable
    {
        get 
        {
            return false;
        }
    }
}

現(xiàn)在我門就可以調(diào)用AddNumber()這個(gè)方法向服務(wù)端發(fā)送請(qǐng)求來做一個(gè)無刷新的加法運(yùn)算了.
<div style="text-align: center">
        <br />無刷新求和示例<br />
        <br />
        <input id="num1" style="width: 107px" type="text" onkeyup="AddNumber();" value="0"  />
        +<input id="num2" style="width: 95px" type="text"  onkeyup="AddNumber();" value="0"  />
        =<input id="sum" style="width: 97px" type="text" /></div>
運(yùn)行結(jié)果如下:

這個(gè)實(shí)例雖然很簡(jiǎn)單.我之所以用這個(gè)實(shí)例主要是給大家介紹XmlHttp對(duì)象的處理過程.文章后面我把項(xiàng)目文件提供下載.

------------------------------------------------------------------------------------------------------------
      上面把JS寫到頁(yè)面中了,在實(shí)際的項(xiàng)目開發(fā)中是不推薦這樣做的,最好把JS代碼都定義到一個(gè)JS文件類.我這里有一份XmlHttpRequest對(duì)象的JS(網(wǎng)上下載的),把相關(guān)的方法基本都寫全了.下面我門來看看怎么使用這個(gè)外部JS文件來發(fā)送異步請(qǐng)求及響應(yīng).
我門先來看看這個(gè)JS文件的詳細(xì)定義:
 1
function CallBackObject()
 2
{
 3
  this.XmlHttp = this.GetHttpObject();
 4
}
 5
 
 6
CallBackObject.prototype.GetHttpObject = function()
 7

 8
  var xmlhttp;
 9
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
10
    try {
11
      xmlhttp = new XMLHttpRequest();
12
    } catch (e) {
13
      xmlhttp = false;
14
    }
15
  }
16
  return xmlhttp;
17
}
18
 
19
CallBackObject.prototype.DoCallBack = function(URL)
20

21
  ifthis.XmlHttp )
22
  {
23
    ifthis.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
24
    {
25
      var oThis = this;
26
      this.XmlHttp.open('POST', URL);
27
      this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
28
      this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
29
      this.XmlHttp.send(null);
30
    }
31
  }
32
}
33
 
34
CallBackObject.prototype.AbortCallBack = function()
35
{
36
  ifthis.XmlHttp )
37
    this.XmlHttp.abort();
38
}
39
 
40
CallBackObject.prototype.OnLoading = function()
41
{
42
  // Loading
43
}
44
 
45
CallBackObject.prototype.OnLoaded = function()
46
{
47
  // Loaded
48
}
49
 
50
CallBackObject.prototype.OnInteractive = function()
51
{
52
  // Interactive
53
}
54
 
55
CallBackObject.prototype.OnComplete = function(responseText, responseXml)
56
{
57
  // Complete
58
}
59
 
60
CallBackObject.prototype.OnAbort = function()
61
{
62
  // Abort
63
}
64
 
65
CallBackObject.prototype.OnError = function(status, statusText)
66
{
67
  // Error
68
}
69
 
70
CallBackObject.prototype.ReadyStateChange = function()
71
{
72
  ifthis.XmlHttp.readyState == 1 )
73
  {
74
    this.OnLoading();
75
  }
76
  else ifthis.XmlHttp.readyState == 2 )
77
  {
78
   this.OnLoaded();
79
  }
80
  else ifthis.XmlHttp.readyState == 3 )
81
  {
82
   this.OnInteractive();
83
  }
84
  else ifthis.XmlHttp.readyState == 4 )
85
  {
86
   ifthis.XmlHttp.status == 0 )
87
      this.OnAbort();
88
    else ifthis.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK" )
89
      this.OnComplete(this.XmlHttp.responseText, this.XmlHttp.responseXML);
90
    else
91
      this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);   
92
  }
93
}
94

一個(gè)簡(jiǎn)單的Hello實(shí)例:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HelloWorld實(shí)例</title>
<script language="jscript" src="CallBackObject.js"></script>
        <script language=jscript>
        
function createRequest()
        
{
            
var name = escape(document.getElementById("name").value);
            
var cbo = new CallBackObject();
            cbo.OnComplete 
= Cbo_Complete;
            cbo.onError 
= Cbo_Error;
            cbo.DoCallBack(
"HelloWorldServer.aspx?name=" + name);                        
        }


        
function Cbo_Complete(responseText, responseXML)
        
{
            alert(responseText);
        }


        
function Cbo_Error(status, statusText, responseText)
        
{
            alert(responseText);
        }

        
</script>
</head>
<body>
    <form id="form1" runat="server">
    <DIV style="DISPLAY: inline; FONT-WEIGHT: bold; FONT-SIZE: 30px; FONT-FAMILY: Arial, Verdana"
                ms_positioning
="FlowLayout">Hello, Ajax!</DIV>
            <HR width="100%" SIZE="1">
            <input type="text" id="name">
            <br>
            <input type="button" value="發(fā)送請(qǐng)求" onclick="javascript:createRequest()">
    </form>
</body>
</html>

     關(guān)于XmlHttpRequest對(duì)象就介紹到這里,更多更詳細(xì)的內(nèi)容請(qǐng)大家查看相關(guān)資料.
     歡迎拍磚指正,不甚感激!
本文實(shí)例源代碼下載
posted on 2008-03-29 15:49 Bēniaǒ 閱讀(4091) 評(píng)論(8) 編輯 收藏

評(píng)論:
#1樓[樓主] 2008-03-29 15:52 | Bēniaǒ  
補(bǔ)上Hello實(shí)例的服務(wù)器端代碼:
protected void Page_Load(object sender, EventArgs e)
{
string strName = HttpContext.Current.Request.QueryString["name"];
string strRes = "服務(wù)器返回的響應(yīng)信息:\r\n" +
"Hello, " + strName + "!";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strRes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
  
#2樓 2008-05-14 10:00 | point.deng  
安逸。我下來看看呢。`
  
#3樓 2008-05-14 10:14 | point.deng  
AddHandler.ashx這種文件來處理我還沒用過,嘿嘿。高!學(xué)習(xí)了~
  
#4樓 2008-05-14 10:16 | point.deng  
對(duì)了,用這種文件來處理有什么好處嗎?除了簡(jiǎn)單,好看以外?
  
#5樓[樓主] 2008-05-14 15:07 | Bēniaǒ  
@成長(zhǎng)的強(qiáng)強(qiáng)
強(qiáng)強(qiáng) ....郁悶得很....我著感冒了..
  
#6樓[樓主] 2008-05-14 15:09 | Bēniaǒ  
@成長(zhǎng)的強(qiáng)強(qiáng)
.ashx 文件用于寫web handler的。其實(shí)就是帶HTML和C#的混合文件。
同樣.aspx也可以代替他的,不過在使用.aspx的時(shí)候必須得
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();

不然返回的數(shù)據(jù)出了你需要的數(shù)據(jù)外,它還把它自身的html碼和一起返回了.
  
#7樓 2008-05-15 09:19 | point.deng  
哦,。這個(gè)細(xì)節(jié)我沒注意到呢。

你感冒了呀,是不是四川的地震后爆發(fā)出的瘟疫喲?
  
#8樓[樓主] 2008-05-16 01:36 | Bēniaǒ  
@成長(zhǎng)的強(qiáng)強(qiáng)

輕松掌握XMLHttpRequest對(duì)象

XmlHttp是什么?

      最通用的定義為:XmlHttp是一套可以在Javascript、VbScript、Jscript等腳本語(yǔ)言中通過http協(xié)議傳送或從接收XML及其他數(shù)據(jù)的一套API。XmlHttp最大的用處是可以更新網(wǎng)頁(yè)的部分內(nèi)容而不需要刷新整個(gè)頁(yè)面。

來自MSDN的解釋:XmlHttp提供客戶端同http服務(wù)器通訊的協(xié)議。客戶端可以通過XmlHttp對(duì)象(MSXML2.XMLHTTP.3.0)向http服務(wù)器發(fā)送請(qǐng)求并使用微軟XML文檔對(duì)象模型Microsoft? XML Document Object Model (DOM)處理回應(yīng)。 現(xiàn)在的絕對(duì)多數(shù)瀏覽器都增加了對(duì)XmlHttp的支持,IE中使用ActiveXObject方式創(chuàng)建XmlHttp對(duì)象,其他瀏覽器如:Firefox、Opera等通過window.XMLHttpRequest來創(chuàng)建xmlhttp對(duì)象。

XmlHttp對(duì)象的屬性:


XmlHttp對(duì)象的方法:


如何發(fā)送一個(gè)簡(jiǎn)單的請(qǐng)求?
      最簡(jiǎn)單的請(qǐng)求是,不以查詢參數(shù)或提交表單的方式向服務(wù)器發(fā)送任何信息.使用XmlHttpRequest對(duì)象發(fā)送請(qǐng)求的基本步驟:
      ● 為得到XmlHttpRequest對(duì)象實(shí)例的一個(gè)引用,可以創(chuàng)建一個(gè)新的XmlHttpRequest的實(shí)例。
      ● 告訴XmlHttpRequest對(duì)象,那個(gè)函數(shù)回處理XmlHttpRequest對(duì)象的狀態(tài)的改變.為此要把對(duì)象的
         onreadystatechange屬性設(shè)置為指向JavaScript的指針.
      ● 指定請(qǐng)求屬性.XmlHttpRequest對(duì)象的Open()方法會(huì)指定將發(fā)送的請(qǐng)求.
      ● 將請(qǐng)求發(fā)送給服務(wù)器.XmlHttpRequest對(duì)象的send()方法將請(qǐng)求發(fā)送到目標(biāo)資源.

XmlHttpRequest實(shí)例分析
      我想大家都知道,要想使用一不對(duì)象首先我門得做什么?是不是必須先創(chuàng)建一個(gè)對(duì)象吧.比如C#和Java里用new來實(shí)例對(duì)象.那么我門現(xiàn)在要使用XmlHttp對(duì)象是不是也應(yīng)該先創(chuàng)建一個(gè)XmlHttp對(duì)象呢?這是毫無疑問的!那么下面我們來看看在客戶端怎么創(chuàng)建一個(gè)XmlHttp對(duì)象,并使用這個(gè)對(duì)象向服務(wù)端發(fā)送Http請(qǐng)求,然后處理服務(wù)器返回的響應(yīng)信息.

1.創(chuàng)建一個(gè)XmlHttp對(duì)象(在這里我以一個(gè)無刷新做加法運(yùn)算的實(shí)例 )

 1
var xmlHttp;
 2
function createXMLHttpRequest()
 3
{
 4
   if(window.ActiveXObject)
 5
   {
 6
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 7
   }
 8
   else if(window.XMLHttpRequest)
 9
   {
10
      xmlHttp = new XMLHttpRequest();
11
   }
12
}

2.定義發(fā)送請(qǐng)求的方法

1
//處理方法
2
function AddNumber()
3
{
4
  createXMLHttpRequest();
5
  var url= "AddHandler.ashx?num1="+document.getElementById("num1").value+"&num2="+document.getElementById("num2").value;
6
  xmlHttp.open("GET",url,true);
7
  xmlHttp.onreadystatechange=ShowResult;
8
  xmlHttp.send(null);
9
}

3.定義回調(diào)函數(shù),用于處理服務(wù)端返回的信息

 1
//回調(diào)方法
 2
function ShowResult()
 3
{
 4
   if(xmlHttp.readyState==4)
 5
   {
 6
      if(xmlHttp.status==200)
 7
      {
 8
          document.getElementById("sum").value=xmlHttp.responseText;
 9
      }
10
   }
11
}
      在上面這個(gè)實(shí)例中,是在客戶端想服務(wù)端的AddHandler.ashx發(fā)送的請(qǐng)求,并傳遞兩個(gè)參數(shù)(也就是待相加的數(shù))過去,下面我門來看看服務(wù)端是怎么處理接收傳遞過去的兩個(gè)參數(shù)以及怎么實(shí)現(xiàn)加法運(yùn)算并返回結(jié)果到客戶端的.代碼如下:
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;

public class Handler : IHttpHandler 
{
    
    public void ProcessRequest (HttpContext context) 
    {
        context.Response.ContentType = "text/plain";
        int a = Convert.ToInt32(context.Request.QueryString["num1"]);
        int b = Convert.ToInt32(context.Request.QueryString["num2"]);
        int result = a + b;
        context.Response.Write(result);
    }
 
    public bool IsReusable
    {
        get 
        {
            return false;
        }
    }
}

現(xiàn)在我門就可以調(diào)用AddNumber()這個(gè)方法向服務(wù)端發(fā)送請(qǐng)求來做一個(gè)無刷新的加法運(yùn)算了.
<div style="text-align: center">
        <br />無刷新求和示例<br />
        <br />
        <input id="num1" style="width: 107px" type="text" onkeyup="AddNumber();" value="0"  />
        +<input id="num2" style="width: 95px" type="text"  onkeyup="AddNumber();" value="0"  />
        =<input id="sum" style="width: 97px" type="text" /></div>
運(yùn)行結(jié)果如下:

這個(gè)實(shí)例雖然很簡(jiǎn)單.我之所以用這個(gè)實(shí)例主要是給大家介紹XmlHttp對(duì)象的處理過程.文章后面我把項(xiàng)目文件提供下載.

------------------------------------------------------------------------------------------------------------
      上面把JS寫到頁(yè)面中了,在實(shí)際的項(xiàng)目開發(fā)中是不推薦這樣做的,最好把JS代碼都定義到一個(gè)JS文件類.我這里有一份XmlHttpRequest對(duì)象的JS(網(wǎng)上下載的),把相關(guān)的方法基本都寫全了.下面我門來看看怎么使用這個(gè)外部JS文件來發(fā)送異步請(qǐng)求及響應(yīng).
我門先來看看這個(gè)JS文件的詳細(xì)定義:
 1
function CallBackObject()
 2
{
 3
  this.XmlHttp = this.GetHttpObject();
 4
}
 5
 
 6
CallBackObject.prototype.GetHttpObject = function()
 7

 8
  var xmlhttp;
 9
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
10
    try {
11
      xmlhttp = new XMLHttpRequest();
12
    } catch (e) {
13
      xmlhttp = false;
14
    }
15
  }
16
  return xmlhttp;
17
}
18
 
19
CallBackObject.prototype.DoCallBack = function(URL)
20

21
  ifthis.XmlHttp )
22
  {
23
    ifthis.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
24
    {
25
      var oThis = this;
26
      this.XmlHttp.open('POST', URL);
27
      this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
28
      this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
29
      this.XmlHttp.send(null);
30
    }
31
  }
32
}
33
 
34
CallBackObject.prototype.AbortCallBack = function()
35
{
36
  ifthis.XmlHttp )
37
    this.XmlHttp.abort();
38
}
39
 
40
CallBackObject.prototype.OnLoading = function()
41
{
42
  // Loading
43
}
44
 
45
CallBackObject.prototype.OnLoaded = function()
46
{
47
  // Loaded
48
}
49
 
50
CallBackObject.prototype.OnInteractive = function()
51
{
52
  // Interactive
53
}
54
 
55
CallBackObject.prototype.OnComplete = function(responseText, responseXml)
56
{
57
  // Complete
58
}
59
 
60
CallBackObject.prototype.OnAbort = function()
61
{
62
  // Abort
63
}
64
 
65
CallBackObject.prototype.OnError = function(status, statusText)
66
{
67
  // Error
68
}
69
 
70
CallBackObject.prototype.ReadyStateChange = function()
71
{
72
  ifthis.XmlHttp.readyState == 1 )
73
  {
74
    this.OnLoading();
75
  }
76
  else ifthis.XmlHttp.readyState == 2 )
77
  {
78
   this.OnLoaded();
79
  }
80
  else ifthis.XmlHttp.readyState == 3 )
81
  {
82
   this.OnInteractive();
83
  }
84
  else ifthis.XmlHttp.readyState == 4 )
85
  {
86
   ifthis.XmlHttp.status == 0 )
87
      this.OnAbort();
88
    else ifthis.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK" )
89
      this.OnComplete(this.XmlHttp.responseText, this.XmlHttp.responseXML);
90
    else
91
      this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);   
92
  }
93
}
94

一個(gè)簡(jiǎn)單的Hello實(shí)例:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>HelloWorld實(shí)例</title>
<script language="jscript" src="CallBackObject.js"></script>
        <script language=jscript>
        
function createRequest()
        
{
            
var name = escape(document.getElementById("name").value);
            
var cbo = new CallBackObject();
            cbo.OnComplete 
= Cbo_Complete;
            cbo.onError 
= Cbo_Error;
            cbo.DoCallBack(
"HelloWorldServer.aspx?name=" + name);                        
        }


        
function Cbo_Complete(responseText, responseXML)
        
{
            alert(responseText);
        }


        
function Cbo_Error(status, statusText, responseText)
        
{
            alert(responseText);
        }

        
</script>
</head>
<body>
    <form id="form1" runat="server">
    <DIV style="DISPLAY: inline; FONT-WEIGHT: bold; FONT-SIZE: 30px; FONT-FAMILY: Arial, Verdana"
                ms_positioning
="FlowLayout">Hello, Ajax!</DIV>
            <HR width="100%" SIZE="1">
            <input type="text" id="name">
            <br>
            <input type="button" value="發(fā)送請(qǐng)求" onclick="javascript:createRequest()">
    </form>
</body>
</html>

     關(guān)于XmlHttpRequest對(duì)象就介紹到這里,更多更詳細(xì)的內(nèi)容請(qǐng)大家查看相關(guān)資料.
     歡迎拍磚指正,不甚感激!
本文實(shí)例源代碼下載
posted on 2008-03-29 15:49 Bēniaǒ 閱讀(4091) 評(píng)論(8) 編輯 收藏

評(píng)論:
#1樓[樓主] 2008-03-29 15:52 | Bēniaǒ  
補(bǔ)上Hello實(shí)例的服務(wù)器端代碼:
protected void Page_Load(object sender, EventArgs e)
{
string strName = HttpContext.Current.Request.QueryString["name"];
string strRes = "服務(wù)器返回的響應(yīng)信息:\r\n" +
"Hello, " + strName + "!";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strRes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
  
#2樓 2008-05-14 10:00 | point.deng  
安逸。我下來看看呢。`
  
#3樓 2008-05-14 10:14 | point.deng  
AddHandler.ashx這種文件來處理我還沒用過,嘿嘿。高!學(xué)習(xí)了~
  
#4樓 2008-05-14 10:16 | point.deng  
對(duì)了,用這種文件來處理有什么好處嗎?除了簡(jiǎn)單,好看以外?
  
#5樓[樓主] 2008-05-14 15:07 | Bēniaǒ  
@成長(zhǎng)的強(qiáng)強(qiáng)
強(qiáng)強(qiáng) ....郁悶得很....我著感冒了..
  
#6樓[樓主] 2008-05-14 15:09 | Bēniaǒ  
@成長(zhǎng)的強(qiáng)強(qiáng)
.ashx 文件用于寫web handler的。其實(shí)就是帶HTML和C#的混合文件。
同樣.aspx也可以代替他的,不過在使用.aspx的時(shí)候必須得
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();

不然返回的數(shù)據(jù)出了你需要的數(shù)據(jù)外,它還把它自身的html碼和一起返回了.
  
#7樓 2008-05-15 09:19 | point.deng  
哦,。這個(gè)細(xì)節(jié)我沒注意到呢。

你感冒了呀,是不是四川的地震后爆發(fā)出的瘟疫喲?
  
#8樓[樓主] 2008-05-16 01:36 | Bēniaǒ  
@成長(zhǎng)的強(qiáng)強(qiáng)
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
追求簡(jiǎn)約而且簡(jiǎn)單的AJAX封裝:Prototype
建一個(gè)XMLHttpRequest對(duì)象池
對(duì)onreadystatechange屬性的理解
常用的javascript設(shè)計(jì)模式
javascript的prototype
Javascript+XMLHttpRequest+asp
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服