Ajax ÔÚÓû§¿Ø¼þÖеÄÓ¦Óã¨ÒÔGoogle SuggestΪÀý£©
ʼþ´¥·¢£º
<input name="keyword" onkeyup="LoadResults(this.value)" id="keyword" runat="server"/>
¿Í»§¶ËÖ÷Ì壺
//¶¨ÒåÓû§¿Ø¼þIDÈ«¾Ö±äÁ¿
var ClientID;
function ShowDiv(divid)
{
//...
}
function HideDiv(divid)
{
//...
}
//Ò³Ãæ¼ÓÔØʱµÄ´¦Àí
function BodyLoad()
{
HideDiv(ClientID + "searchresults");
var findtextbox = document.getElementById(ClientID + "keyword");
findtextbox.focus();
}
function ClearResults()
{
//...£¨Ñ°ÕÒÔªËØʱIDÇ°¾ù¼Ó ClientID£©
}
function LoadResults(searchterm)
{
//...
// Ç°¼ÓÒ»¸öClientID×÷Ϊ²ÎÊý
Anthem_InvokeControlMethod(
"<%= ClientID %>",
'RetrieveRows',
[searchterm],
LoadResultsCallback);
}
function LoadResultsCallback(result)
{
//...£¨Ñ°ÕÒÔªËØʱIDÇ°¾ù¼Ó ClientID£©
}
function ReplaceInput(tablecell)
{
//...£¨Ñ°ÕÒÔªËØʱIDÇ°¾ù¼Ó ClientID£©
}
·þÎñÆ÷¶ËÖ÷Ì壺
protected void Page_Load(object sender, EventArgs e)
{
Anthem.Manager.Register(this); //×¢²áAnthem
}
[Anthem.Method] // ÉùÃ÷ΪAnthemÇ°¶Ë¿É¸ÐÖªµÄ·½·¨
public DataTable RetrieveRows(string searchterm)
{
//...
}
//ÖØÔØÒ³ÃæOnInitʼþ
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//»ñÈ¡ClientIDÖµ
string jcode = "<mce:script language=\"javascript\" type=\"text/javascript\"><!--
ClientID = '" + this.ClientID + "_" + "';BodyLoad();
// --></mce:script>";
//¸ø¿Í»§¶ËÒ³ÃæÌí¼Ójs´úÂ룬ʹǰ¶ËµÃµ½ClientID±äÁ¿Öµ
Page.ClientScript.RegisterStartupScript(typeof(Page),"suggest_control", jcode);
}
Ïà¹ØÎĵµ£º
×î½üÍøÉÏÌáµÄºÜ¶àµÄÒ»¸öиÅÄî¾ÍÊÇ AJAX ÁË, ÄÇô, AJAX ÊÇʲôÄØ? ÒÔÏÂÄÚÈÝÒýÓÃÍøÉÏ×ÊÁÏ:
AJAXÈ«³ÆΪ“Asynchronous JavaScript and XML”£¨Òì²½JavaScriptºÍXML£©£¬ÊÇÖ¸Ò»ÖÖ´´½¨½»»¥Ê½ÍøÒ³Ó¦ÓõÄÍøÒ³¿ª·¢¼¼Êõ¡£ËüÓлúµØ°üº¬ÁËÒÔϼ¸ÖÖ¼¼Êõ£º
Ajax£¨Asynchronous JavaScript + XML£©µÄ¶¨Òå
»ùÓÚ web±ê×¼£¨sta ......
Ò»¡¢ н¨Ò»¸öAjax_StartµÄÍøÕ¾
¶þ¡¢ ÔÚÍøÕ¾ÖÐÌí¼ÓÒ»¸öweb·þÎñ£¨ws_start.asmx£©
ÔÚvs2008ÖУ¬Ìí¼ÓÒ»¸öweb·þÎñÉú³ÉÁËÁ½¸öÎļþ£¬Ò»¸öÊÇasmxÎļþ£¬Ò»¸öÊÇÔÚApp_codeÀïµÄcsÎļþ£»ÎÒ¾õµÃÕâÑù²¢²»ºÃ£¬Ö ......
Ajaxµ÷ÓÃÔ¶³Ì·þÎñÆ÷Êý¾Ý»á³öÏ־ܾø·ÃÎʵÄÎÊÌâ¡£ÕâÊÇÒòΪ»ùÓÚ°²È«µÄ¿¼ÂÇ£¬AJAXÖ»ÄÜ·ÃÎʱ¾ÓòϵÄ×ÊÔ´£¬¶ø²»ÄÜ¿çÓò·ÃÎÊ¡£Ò²¾ÍÊÇ˵£¬domain1.comÕ¾µãÖеÄAJAXÖ»ÄÜ·ÃÎÊdomain1.comÕ¾µãϵÄ×ÊÔ´,¶ø²»ÄÜ¿çÓò·ÃÎÊdomain2.comÕ¾µãÖеÄ×ÊÔ´£¬Õâ¾ÍÊÇAJAX¿çÓòÎÊÌâ¡£
½â¾ö˼·£ºÒ³ÃæÔÚÌá½»ÇëÇóʱ ......
Background For the basic of how to create an AJAX enabled WCF service, please refer to MSDN: http://msdn.microsoft.com/en-us/library/bb924552.aspx. For the basic of JSONP, please refer to: http://en.wikipedia.org/wiki/JSON#JSONP. This article introduce how to make AJAX enabled WCF service support cr ......