AJAX ÎÞË¢ÐÂ
ICallbackEventHandler
aspx Ò³Ã棺
function CallServer(PhotoId)
{
document.getElementById("updatediv").style.display = "block";
document.getElementById("txtPhotoID").value = PhotoId;
var product = document.all("txtPhotoID").value;
<%= ClientScript.GetCallbackEventReference(this, "product", "ReceiveServerData",null)%>;
}
function ReceiveServerData(PhotoInfo)
{
if(PhotoInfo!="")
{
var result="";
var str=PhotoInfo;
var Photo=str.split("^&^");
for(i=0;i<Photo.length;i++)
{
result += Photo[i];
}
document.getElementById("txtPhotoName").value=Photo[0];
document.getElementById("txtPhotoDescr").value=Photo[1];
}else{("ÇëÑ¡ÔñÐèÒªÐ޸ĵÄÏàƬ£¡");}
}
.cs Ò³Ãæ
string ICallbackEventHandler.GetCallbackResult()
{
return Server.UrlDecode(CallBackValue)+"^&^"+Server.UrlDecode(CallPhotoColltion);
}
void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
{
int PhotoID = int.Parse(eventArgument);
PhotoInfo = Photo.GetModel(PhotoID);
string PhotoName = PhotoInfo.PhotoName;
CallBackValue = Server.UrlDecode(PhotoName);
string PhotoIntroduction = PhotoInfo.PhotoIntroduction;
CallPhotoColltion = Server.UrlDecode(Phot
Ïà¹ØÎĵµ£º
£¨×ªÌû£©
¡¡¡¡Ò»Ìáµ½ÈçºÎÔÚǰ̨JSµ÷Óúǫ́C#·½·¨£¬AJAX³ÉΪÁ˱ØÈ»µÄÏë·¨¡£
¡¡¡¡Ö»ÊÇʵÏÖµÄϸ½Ú²ÉÓÃAJAX 1.0»òÕßAjaxProµÄÇø±ð¡£
¡¡¡¡ÆäʵÈç¹û²»ÓÃAJAX£¬ÎÒÃÇÒ²Äܹ»ºÜ·½±ãµØÀûÓÃJSµ÷Óúǫ́·½·¨¡£
¡¡¡¡²½ÖèÈçÏ£º
¡¡¡¡1 ǰ̨·ÅÒ»¸ö°´Å¥¡£ÉèÖÃΪÒþ²Ø¡£×¢Ò⣺²»ÄÜÖ±½ÓÉèÖÃVisible=falseµÄ· ......
¼òµ¥µÄÃèÊöÏ DWR ÅäÖ㨱£ÃÜÐÒ飬Ôڴ˲»¹«¿ªÏîÄ¿Ãû³Æ£¬ÏîÄ¿Ïà¹ØÃû³ÆÈ«²¿ÓÃXXXX´úÌ棩
Ê×ÏÈ ·Ï»°²»ËµÁË ´ó¼Ò¶¼Ó¦¸ÃÀí½âDWRµÄÓô¦ ²»¶®µÄÈ¥°Ù¶È
±ØÒª°ü DWR.JAR ¹Ù·½ÏÂÔصØÖ·http://directwebremoting.org/dwr/download.html
Õâ¸öÏîÄ¿ÊÇÓÉ SSH+dwr+jquery+sitemesh+freemarker
WEB.XML
<!-- dwr -->
<serv ......
AjaxSuggest.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxSuggest.aspx.cs" Inherits="AjaxSuggest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/199 ......
Ò»¡¢ н¨Ò»¸öAjax_StartµÄÍøÕ¾
¶þ¡¢ ÔÚÍøÕ¾ÖÐÌí¼ÓÒ»¸öweb·þÎñ£¨ws_start.asmx£©
ÔÚvs2008ÖУ¬Ìí¼ÓÒ»¸öweb·þÎñÉú³ÉÁËÁ½¸öÎļþ£¬Ò»¸öÊÇasmxÎļþ£¬Ò»¸öÊÇÔÚApp_codeÀïµÄcsÎļþ£»ÎÒ¾õµÃÕâÑù²¢²»ºÃ£¬Ö ......
php´úÂ룺
<?php
¡¡¡¡$arr = array(1, 'ÁõÌì²Å', 22);\
echo json_encode($arr);die();
?>
js:
<script type="text/javascript">
¡¡¡¡function returnObj( info )
¡¡¡¡{
¡¡¡¡¡¡var string = info.responseText;
¡¡¡¡¡¡ var array = eval( ......