日期:2014-05-18  浏览次数:20428 次

AJAX问题!
想自己写一个AJAX请求CS后台方法的功能,是不是需要手写Httphandler然后序列化?
具体是什么流程呢?
请高人指点.

------解决方案--------------------
一、先在web.config中注册AJAXPRO.dll控件
二、在C#Page_Load方法中加载此页的AJAXPRO
三、在HTML中使用client控件编写JS代码调用后台C#中编写的AjaxPro.Method方法
四、要是用web控件的话,在后台直接调用后台的AjaxPro.Method即可
我给你个例子 你自己研究
------解决方案--------------------
学习。。。。UP!
------解决方案--------------------
web.config:
----------------------------
...
<system.web>
<httpHandlers>
<add verb= "POST,GET " path= "ajaxpro/*.ashx " type= "AjaxPro.AjaxHandlerFactory,AjaxPro.2 "/>
</httpHandlers>
...


HTML:
--------------------------------
function nextBtnClick()
{
document.getElementById( "divNext ").style.display = "none ";
document.getElementById( "divEdit ").style.display = "block ";

//AJAX方法调用要修改的记录的数据集
var ds = ajax_GridViewDB.GetDataSource().value;

//用户信息
var uname = document.getElementById( "txtUserName ");
uname.disabled = true;
var upwd = document.getElementById( "userPwd ");
var againpwd = document.getElementById( "againPwd ");
var realname = document.getElementById( "txtRealName ");
var cname = document.getElementById( "txtCompanyName ");
var job = document.getElementById( "dropJob ");
var tel = document.getElementById( "txtTel ");
var email = document.getElementById( "txtEmail ");
var zip = document.getElementById( "txtZip ");
var address = document.getElementById( "txtAddress ");

if(ds!=null)
{
uname.value = ds.Tables[0].Rows[0][ "UserName "];
upwd.value = ds.Tables[0].Rows[0][ "UserPwd "];
againpwd.value = ds.Tables[0].Rows[0][ "UserPwd "];
realname.value = ds.Tables[0].Rows[0][ "RealName "];
cname.value = ds.Tables[0].Rows[0][ "CompanyName "];

//取到该记录的所属行业,并定位在下拉列表相应的index上
var jobName = ds.Tables[0].Rows[0][ "Category "];
for(var i=0; i < job.length; i++)
{
if(job.options[i].value == jobName)
{
job.options[i].selected = true;
}
}

tel.value = ds.Tables[0].Rows[0][ "TelePhone "];
email.value = ds.Tables[0].Rows[0][ "E_mail "];
zip.value = ds.Tables[0].Rows[0][ "Zip "];
address.value = ds.Tables[0].Rows[0][ "Address "];
}
}

<body>
....
<div id= "divNext " style= "display:none ; width: 374px; height: 1px; left: 250px; position: relative; top: 0px; ">
...
<div id= "divEdit " style= "display:none ; font-size:12px; width: 374px; height: 1px; left: 250px; position: relative; top: 0px; ">
...


C#:
-----------------------------------
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(ajax_GridViewDB));
Bind();
}

//得到数据源
[AjaxPro.AjaxMethod]
public DataSet GetDataSource()
{