zoukankan
html css js c++ java
初识AJAX
1、HTML代码:
<%
@ Page language
=
"
c#
"
Codebehind
=
"
Default.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
AjaxTest._Default
"
%>
<!
DOCTYPE HTML PUBLIC
"
-//W3C//DTD HTML 4.0 Transitional//EN
"
>
<
HTML
>
<
HEAD
>
<
title
>
Default
</
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
"
type
=
"
text/javascript
"
>
function getServerTime()
{
document.getElementById(
'
Label1
'
).innerText
=
AjaxTest._Default.GetTime().value ;
}
function add( a,b )
{
var a1
=
parseInt( a );
var b1
=
parseInt( b );
document.getElementById(
'
Label2
'
).innerText
=
AjaxTest._Default.AddTwo( a1,b1 ).value;
}
</
script
>
</
HEAD
>
<
body
>
<
form id
=
"
Form1
"
method
=
"
post
"
runat
=
"
server
"
>
<
table cellpadding
=
"
0
"
cellspacing
=
"
0
"
>
<
tr
>
<
td align
=
"
center
"
height
=
"
100
"
valign
=
"
bottom
"
><
FONT color
=
"
red
"
size
=
"
6
"
>
计算两数之和
</
FONT
></
td
>
</
tr
>
<
tr
>
<
td
>
<
asp:TextBox id
=
"
TextBox1
"
runat
=
"
server
"
></
asp:TextBox
>
<
asp:TextBox id
=
"
TextBox2
"
runat
=
"
server
"
></
asp:TextBox
>
<
input id
=
"
Button
"
type
=
"
button
"
value
=
"
计算两数之和
"
onclick
=
"
add( document.getElementById( 'TextBox1' ).value,document.getElementById( 'TextBox2' ).value )
"
>
</
td
>
</
tr
>
<
tr
>
<
td
><
asp:Label id
=
"
Label2
"
runat
=
"
server
"
Width
=
"
416px
"
Height
=
"
48px
"
></
asp:Label
></
td
>
</
tr
>
<
tr
>
<
td align
=
"
center
"
valign
=
"
bottom
"
height
=
"
100
"
><
FONT color
=
"
red
"
size
=
"
6
"
>
获取服务器时间
</
FONT
></
td
>
</
tr
>
<
tr
>
<
td
><
input id
=
"
Button1
"
type
=
"
button
"
value
=
"
获得服务器时间
"
onclick
=
"
getServerTime();
"
>
<
asp:Label id
=
"
Label1
"
runat
=
"
server
"
Width
=
"
264px
"
></
asp:Label
></
td
>
</
tr
>
</
table
>
</
form
>
</
body
>
</
HTML
>
2、CS代码:
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
namespace
AjaxTest
{
/**/
///
<summary>
///
_Default 的摘要说明。
///
</summary>
public
class
_Default : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.TextBox TextBox1;
protected
System.Web.UI.WebControls.Label Label1;
protected
System.Web.UI.WebControls.Label Label2;
protected
System.Web.UI.WebControls.TextBox TextBox2;
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
AjaxPro.Utility.RegisterTypeForAjax(
typeof
( _Default ) );
}
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
[AjaxPro.AjaxMethod]
public
int
AddTwo(
int
a,
int
b )
{
return
a
+
b;
}
[AjaxPro.AjaxMethod]
public
DateTime GetTime()
{
return
DateTime.Now;
}
}
//
end class
}
3、WEBCONFIG
<
httpHandlers
>
<
add verb
=
"
*
"
path
=
"
*.ashx
"
type
=
"
AjaxPro.AjaxHandlerFactory,AjaxPro
"
/>
</
httpHandlers
>
查看全文
相关阅读:
公共开发中js代码的管理
利用kibana插件对Elasticsearch进行映射
利用kibana插件对Elasticsearch进行批量操作
利用kibana插件对Elasticsearch进行文档和索引的CRUD操作
elasticsearch搜索框架的安装相关
python面试必问 知识整理
Selenium定位不到元素的解决方法—iframe挡住了去路
python 几个简单算法详解
爬虫突破封禁常用方法
转载:使用Tornado+Redis维护ADSL拨号服务器代理池
原文地址:https://www.cnblogs.com/wander/p/476525.html
最新文章
php的cURL库介绍
WIN32 API 获取文件版本信息
VTK 在WINDOWS上的安装使用
MAC NGINX PHP XDEBUG
XDEBUG 选项
mac 显示隐藏文件夹
vs code nginx php xdebug配置
Linux 装完后没有声音的解决办法
将 Ubuntu 16.04 LTS 的 Unity 启动器移动到桌面底部命令
mac mini 装UBUNTU后没有WIFI解决办法
热门文章
使用Group By子句的时候,一定要记住下面的一些规则
jQuery事件之传递参数
js判断undefined类型
(转)jquery.validate使用攻略
oracle 格式化数字 to_char (转)
tomcat下直接访问所有jsp页面均报空指针错误
window.location用法
eclipse中修改tomcat部署位置Server Locations
in 和 exists区别
oracle materialized view 物化视图
Copyright © 2011-2022 走看看