以前都沒有用過AJaxPro,今天試試效果,呵呵!
下載AJaxPro.2.dll
官方網站:http://www.codeplex.com/AJaxPro
1,在我們的web站點中,添加引用,加入AJaxPro.2.dll
2,配置web.config
在system.web節點下,添加如下節點:
vIEw plaincopy to clipboardprint?
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AJaxPro.2"/>
</httpHandlers>
<httpHandlers>
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AJaxPro.2"/>
</httpHandlers>
3,在Page_Load事件中注冊頁面類型:
vIEw plaincopy to clipboardprint?
protected void Page_Load(object sender, EventArgs e)
{
//在Page_Load事件中注冊頁面類型
AjaxPro.Utility.RegisterTypeForAJax(typeof(_Default));
}
protected void Page_Load(object sender, EventArgs e)
{
//在Page_Load事件中注冊頁面類型
AjaxPro.Utility.RegisterTypeForAJax(typeof(_Default));
}
4,編寫需要的方法,將方法標記為[AjaxPro.AJaxMethod]:
vIEw plaincopy to clipboardprint?
[AjaxPro.AJaxMethod]
public string Hello()
{
return "Hello,Now is " + DateTime.Now;
}
[AjaxPro.AJaxMethod]
public string Hello()
{
return "Hello,Now is " + DateTime.Now;
}
5,在頁面中寫JS腳本:
vIEw plaincopy to clipboardprint?
<mce:script type="text/Javascript" language="Javascript"><!--
function Hello(){
//AJaxPro.timeoutPeriod=150000 ;
var info = "請稍候,正在處理數據...";
document.getElementById('info').innerHtml=info;
_Default.Hello(CallBack);
}
function CallBack(mes){
document.getElementById('msg').innerHtml = mes.value;
}
// -->
</mce:script>
<mce:script type="text/Javascript" language="Javascript"><!--
function Hello(){
//AJaxPro.timeoutPeriod=150000 ;
var info = "請稍候,正在處理數據...";
document.getElementById('info').innerHtml=info;
_Default.Hello(CallBack);
}
function CallBack(mes){
document.getElementById('msg').innerHtml = mes.value;
}
// -->
</mce:script>
用到的Html代碼:
vIEw plaincopy to clipboardprint?
<div id="info">
</div>
<div id="msg">
</div>
<div id="info">
</div>
<div id="msg">
</div>
6,調用Hello().