| |||||
|
src="http://aosustudio.com.cn//Upload/Articles/070325/fd048511-18fd-4b65-a776-a48ec09fc11d/faccd019-5221-4abd-80c4-e1969869c7b9.html" frameborder="0" width="100%" scrolling="no" height="270"> | |||||
|
Ajax定义为“Asynchronous JavaScript + XML”的简称,也就是异步的JavaScript和XML处理。从原理上看,主要是Ajax可以通过调用HttpRequest实现与服务器的异步通讯,并最终在网页中实现丰富友好的用户界面
<
httpHandlers
>
<
add
verb
="POST,GET"
path
="ajax/*.ashx"
type
="Ajax.PageHandlerFactory, Ajax"
/>
</
httpHandlers
>
4.在Pages/AjaxTest下建立cs文件AjaxMethod.cs,添加如下方法
//
[Ajax.AjaxMethod]
[Ajax.AjaxMethod(Ajax.HttpSessionStateRequirement.Read)]
public
static
string
GetNIVNumber(
string
str)![]()
{ return str; }
<
HTML
>
<
HEAD
>
<
title
>
AjaxForm
</
title
>
<
meta
name
="GENERATOR"
Content
="Microsoft Visual Studio .NET 7.1"
>
<
meta
name
="CODE_LANGUAGE"
Content
="C#"
>
<
meta
name
="vs_defaultClientScript"
content
="JavaScript"
>
<
meta
name
="vs_targetSchema"
content
="http://schemas.microsoft.com/intellisense/ie5"
>
![]()
<
script
language
="javascript"
>
function testAjax()![]() { var first=document.getElementById("txtfirst"); AjaxMethod.GetNIVNumber(first.value,callback_GetNIVNumber); } function callback_GetNIVNumber(res)![]() { var obj=document.getElementById("txtsecond"); obj.value=res.value; }
</
script
>
</
HEAD
>
<
body
MS_POSITIONING
="GridLayout"
>
<
form
id
="Form1"
method
="post"
runat
="server"
>
<
INPUT
style
="Z-INDEX: 101; LEFT: 208px; POSITION: absolute; TOP: 40px"
type
="button"
value
="Button"
onclick
="testAjax();"
>
<
asp:TextBox
id
="txtfirst"
style
="Z-INDEX: 102; LEFT: 40px; POSITION: absolute; TOP: 40px"
runat
="server"
></
asp:TextBox
>
<
asp:TextBox
id
="txtsecond"
style
="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 72px"
runat
="server"
></
asp:TextBox
>
</
form
>
</
body
>
</
HTML
>
protected
System.Web.UI.WebControls.TextBox txtfirst;
protected
System.Web.UI.WebControls.TextBox txtsecond;
private
void
Page_Load(
object
sender, System.EventArgs e)![]()
{ //注册,其中Document.Pages.AjaxTest.AjaxMethod为AjaxMethod.cs方法所在的命名空间 Ajax.Utility.RegisterTypeForAjax(typeof(Document.Pages.AjaxTest.AjaxMethod)); }
实现效果:在第一个textbox中输入内容,点击button,就把内容显示到第二textbox中。这只是一个简单的示例,还可以修改调用方法,从数据库读取以及更复杂的操作 | |||||
| |||||
|
src="http://aosustudio.com.cn/ad/GoogleSerch.htm" frameborder="0" width="100%" scrolling="no" height="30"> | |||||
★ Ajax使用初步
最新推荐文章于 2026-04-22 10:34:01 发布




}
}
600

被折叠的 条评论
为什么被折叠?



