vs2005 ʹÓÃajax.dll ʵÏÖAjaxÓ¦ÓÃ
1\ÒýÓÃajax.dll»òÕßajaxpro.dllµ½vs2005¹¤³ÌÖÐ
ÔÚweb.configÎļþÖеģ¼system.web£¾¼ÓÈëajaxÉèÖÃ
£¼httpHandlers£¾
¡¡£¼add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/£¾
£¼/httpHandlers£¾
2\±àдajax´úÂë
class _Default
{
[AjaxPro.AjaxMethod] //ÊǶ¨Òå´Ë·½·¨ÎªAjax¿Éµ÷Óõķ½·¨,ÊDZØÐëҪעÃ÷µÄ
public string SetTb(string name)
{
return name;
}
}
3\Ò³Ãæ¼ÓÔØÖÐ ×¢²áAJAX¿Éµ÷ÓõÄÀàµÄÃû³Æ
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
}
4\ajax·½·¨Ôڽű¾Öе÷ÓÃ
£¼script language="javascript" type="text/javascript"£¾
function comit_onclick()
{
¡¡ var name=document.getElementById("tb1").value;
¡¡ _Default.SetTb(name,callback);//ajax·½·¨µ÷ÓÃ,nameΪʵ¼Ê²ÎÊý,callback½ÓÊÜ·µ»ØÖµ
}
function callback(res)
{
¡¡document.getElementById("tb").value=res.value;
}
£¼/script£¾
Ïà¹ØÎĵµ£º
ASP.NET,AJAXÎļþÉÏ´«µÄÒÉÎÊ
Ô±¾ÒÔΪÓÃÕâÖÖ·½Ê½£¬°Ñ´Ë·½·¨·Åµ½Ò»¸öHttphandlerÖУ¬È»ºó´ÓJAVASCRIPT·ÃÎÊHttphandlerÀ´ÊµÏÖÎÞˢеÄÎļþÉÏ´«¡£Ã»Ïëµ½£¬ÕâÑùͬÑùÊDz»Ðеģ¬Ö»ÄÜÔÚ±¾»ú²âÊÔͨ¹ý£¬Èç¹û·Åµ½ÍøÉÏ£¬»òÕß´ÓÆäËûµØ·½·ÃÎʾͻáÌáʾÎÞ·¨ÕÒµ½Îļþ£¬¿É¼ûÔÚASP.NETÖÐËüÖ»ÄÜÓÃÓÚÉÏ´«·þÎñÆ÷¶ËµÄÎļþ¡£
֮ǰÔÚÍøÕ¾Ò²Ë ......
AJAX (Òì²½ JavaScript ºÍ XML) ÊǸöвúÉúµÄÊõÓï,רΪÃèÊöJavaScriptµÄÁ½ÏîÇ¿´óÐÔÄÜ.ÕâÁ½ÏîÐÔ
ÄÜÔÚ¶àÄêÀ´Ò»Ö±±»ÍøÂ翪·¢ÕßËùºöÂÔ,Ö±µ½×î½üGmail, Google suggestºÍgoogle MapsµÄºá¿Õ³öÊÀ²ÅʹÈË
ÃÇ¿ªÊ¼Òâʶµ½ÆäÖØÒªÐÔ.
ÕâÁ½Ïî±»ºöÊÓµÄÐÔÄÜÊÇ:
* ÎÞÐèÖØÐÂ×°ÔØÕû¸öÒ³Ãæ±ãÄÜÏò·þÎñÆ÷·¢ËÍÇëÇó.
* ¶ÔXMLÎĵµµÄ½âÎöºÍ´¦Àí£®
......
ÎÒÓÃPHPºÍAjax½áºÏ£¬Ìí¼ÓÊý¾ÝÖ®ºó£¬Ë¢ÐÂǰ̨ҳÃ棬Êý¾ÝûÓб仯¡£
ÎҸĶ¯PHP¶¯Ì¬½Å±¾£¬Ö»ÓÐÖØÐÂÕÒ¿ªIEÔÙÊäÈëµØÖ·£¬²ÅÄÜ¿´µ½Ð§¹û¡£
ÒÔÉÏÕâЩÊDz»ÊÇ»º´æµÄÔÒò°¡£¿Ôõô½â¾ö£¿
ajax»º´æÎÊÌâ½â¾ö;¾¶£º
ÊÇ»º´æµÄÎÊÌâ¡£
ÔÚ·þÎñ¶Ë¼Ó header("Cache-Control: no-cache, must-revalidate");
²¢ÇÒÔÚÄãµÄJSÌá½»²ÎÊýÖмÓËæ»ú» ......
Ajax¼¼ÊõÒѾµÃµ½ºÜ¹ã·ºµÄÓ¦Óã¬ÔÚWeb¿ª·¢ÖÐÆäºËÐľÍÔÚÓÚÒ첽ͨÐź;ֲ¿Ë¢Ð£¬¼«´óµØ¸ÄÉÆÁËÓû§ÌåÑ飬ÓÈÆäÊʺÏÓÚ¸ßƵ¶È¡¢µÍÊý¾ÝÁ¿µÄ³¡¾°¡£ÔÚ²»Ê¹ÓÃAjaxµÄWebÓ¦ÓÃÖУ¬Ò»¸öÒ³Ãæ´¦ÀíÖÐÖ»ÓÐÒ»´ÎÇëÇ󣬿ͻ§¶Ë´¦ÀíÍêºóÒ»´ÎÐÔÌá½»£¬ÕâÖÖÒ»´ÎÇëÇóºÍÒ»´ÎÌá½»µÄ´¦Àí¿ÉÄܱȽϺÄʱ£¬´Ó¶øÔì³É¿Í»§µÈ´ý£¬Ê¹ÓÃAjax°ÑÕâÒ»´ÎÇëÇóºÍÒ»´ÎÌá½»·Ö ......
ajax.asp
ÏÖÔÚʱ¼äÊÇ< %=Now()%>
ajax.html
<script type="text/javascript">
function Ajax(){
var xmlHttp=null;
if(window.ActiveXObject){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
......