1. 我在web.config 中的 <system.web>节点中加入
<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro"/>
</httpHandlers>2. 在namespace为 Test,类名为TestAjax的cs文件中加入 [AjaxPro.AjaxMethod]
using System;namespace Test
{
public class TestAjax
{
public TestAjax()
{
} [AjaxPro.AjaxMethod]
public string GetString()
{
return "this is a ajax method!";
} }
}3. 在 index.aspx 中的 index.aspx.cs Page_Load中加入如下代码
namespace Test
{
/// <summary>
/// index 的摘要说明。
/// </summary>
public class index : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Test.TestAjax));
} }
}4.在 index.aspx的html的中将<form id="Form1" method="post" runat="server"></from>改成如下代码
<form id="Form1" method="post" runat="server">
<script language=javascript>
window.onload = function()
{
var res = Test.TestAjax.GetString().value;
alert(res);
}
</script>
</from>本地测试可用 上传到服务器后 var res = Test.TestAjax.GetString().value;
出错提示 Test未定义
<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro"/>
</httpHandlers>2. 在namespace为 Test,类名为TestAjax的cs文件中加入 [AjaxPro.AjaxMethod]
using System;namespace Test
{
public class TestAjax
{
public TestAjax()
{
} [AjaxPro.AjaxMethod]
public string GetString()
{
return "this is a ajax method!";
} }
}3. 在 index.aspx 中的 index.aspx.cs Page_Load中加入如下代码
namespace Test
{
/// <summary>
/// index 的摘要说明。
/// </summary>
public class index : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(Test.TestAjax));
} }
}4.在 index.aspx的html的中将<form id="Form1" method="post" runat="server"></from>改成如下代码
<form id="Form1" method="post" runat="server">
<script language=javascript>
window.onload = function()
{
var res = Test.TestAjax.GetString().value;
alert(res);
}
</script>
</from>本地测试可用 上传到服务器后 var res = Test.TestAjax.GetString().value;
出错提示 Test未定义
解决方案 »
- 在js动态获取后台属性的值,谢谢
- 引用的office怎么发布
- ASP母版页的后台怎么获取页面的DIV,div是服务器端的
- 对于打DATASET中新增的一对记录,并将其存到数据库中,其记录状态是怎么变化的?
- 如何动态控制控件的位置
- 公司要求开发一个Blog,用.net开发,思路不是很清晰,向各位大侠请求支援,顶者有分!
- 如何获取某一存储过程所有的参数列表呢?
- 怎样得到当前登陆到Active Directory控制域用户的用户名。进者有分,在线等!
- global中的Application对象可以使用数组吗?
- DATAGRID绑定数据后(自动创建列),如何用代码设置某一列的visible属性?
- 删除虚拟目录
- 如何去除网页代码中的所有链接(保持文字),包括图片链接文字链接等
这是服务端的用法.