jQuery Ajax È«½âÎö
ÎÄÕ³ö×Ô£ºhttp://www.cnblogs.com/QLeelulu/archive/2008/04/21/1163021.html
±¾ÎĵØÖ·: jQuery
Ajax È«½âÎö
±¾ÎÄ×÷ÕߣºQLeelulu
תÔØÇë±êÃ÷³ö´¦£¡
jQueryȷʵÊÇÒ»¸öͦºÃµÄÇáÁ¿¼¶µÄJS¿ò¼Ü£¬ÄÜ°ïÖúÎÒÃÇ¿ìËٵĿª·¢JSÓ¦Ó㬲¢ÔÚÒ»¶¨³Ì¶ÈÉϸıäÁËÎÒÃÇдJavaScript´úÂëµÄÏ°¹ß¡£
·Ï»°ÉÙ˵£¬Ö±½Ó½øÈëÕýÌ⣬ÎÒÃÇÏÈÀ´¿´Ò»Ð©¼òµ¥µÄ·½·¨£¬ÕâЩ·½·¨¶¼ÊǶÔjQuery.ajax()½øÐзâ×°ÒÔ·½±ãÎÒÃÇʹÓõķ½·¨£¬µ±È»£¬Èç¹ûÒª´¦Àí¸´
ÔÓµÄÂß¼£¬»¹ÊÇÐèÒªÓõ½jQuery.ajax()µÄ(Õâ¸öºóÃæ»á˵µ½).
1.
load
( url, [data], [callback] ) £ºÔØÈëÔ¶³Ì HTML Îļþ´úÂë²¢²åÈëÖÁ DOM ÖС£
url
(String) : ÇëÇóµÄHTMLÒ³µÄURLµØÖ·¡£
data
(Map) : (¿ÉÑ¡²ÎÊý) ·¢ËÍÖÁ·þÎñÆ÷µÄ key/value Êý¾Ý¡£
callback
(Callback) : (¿ÉÑ¡²ÎÊý) ÇëÇóÍê³Éʱ(²»ÐèÒªÊÇsuccessµÄ
)µÄ»Øµ÷º¯Êý¡£
Õâ¸ö·½·¨Ä¬ÈÏʹÓà GET ·½Ê½À´´«µÝµÄ£¬Èç¹û[data]²ÎÊýÓд«µÝÊý¾Ý½øÈ¥£¬¾Í»á×Ô¶¯×ª»»ÎªPOST·½Ê½µÄ¡£jQuery 1.2
ÖУ¬¿ÉÒÔÖ¸¶¨Ñ¡Ôñ·û£¬À´É¸Ñ¡ÔØÈëµÄ HTML Îĵµ£¬DOM Öн«½ö²åÈëɸѡ³öµÄ HTML ´úÂë¡£Óï·¨ÐÎÈç "url #some >
selector"¡£
Õâ¸ö·½·¨¿ÉÒԺܷ½±ãµÄ¶¯Ì¬¼ÓÔØһЩHTMLÎļþ£¬ÀýÈç±íµ¥¡£
ʾÀý´úÂ룺
$(".ajax.load
").load("http://www.cnblogs.com/QLeelulu/archive/2008/03/30/1130270.html .post
",
function
(responseText, textStatus, XMLHttpRequest){
this
;//ÔÚÕâÀïthisÖ¸ÏòµÄÊǵ±Ç°µÄDOM¶ÔÏ󣬼´$(".ajax.load")[0]
//alert(responseText);//ÇëÇ󷵻صÄÄÚÈÝ
//alert(textStatus);//ÇëÇó״̬£ºsuccess£¬error
//alert(XMLHttpRequest);//XMLHttpRequest¶ÔÏó
});
ÕâÀォÏÔʾ½á¹û¡£
×¢£º
²»ÖªµÀΪʲô
URLд¾ø¶Ô·¾¶ÔÚFFÏ»á³ö´í£¬ÖªµÀµÄÂé·³¸æËßÏ¡£ÏÂÃæµÄget()ºÍpost()ʾÀýʹÓõÄÊǾø¶Ô·¾¶£¬ËùÒÔÔÚFFÏÂÄ㽫»á³ö´í²¢²»»á¿´µ½·µ»Ø½á¹û¡£»¹ÓÐget()ºÍpost()ʾÀý¶¼ÊÇ¿çÓòµ÷Óõģ¬·¢ÏÖ´«ÉÏÀ´ºóû°ì·¨»ñÈ¡½á¹û£¬
ËùÒÔ°ÑÔËÐа´Å¥È¥µôÁË¡£
2. jQuery.get
( url, [data], [callback]
)£ºÊ¹ÓÃGET·½Ê½À´½øÐÐÒì²½ÇëÇó
²ÎÊý£º
url
(String) : ·¢ËÍÇëÇóµÄURLµØÖ·.
data
(Map) : (¿ÉÑ¡) Òª·¢Ë͸ø·þÎñÆ÷µÄÊý¾Ý£¬ÒÔ Key/value
µÄ¼üÖµ¶ÔÐÎʽ±íʾ£¬»á×öΪQueryString¸½¼Óµ½ÇëÇóURLÖС£
callback
(Function) : (¿ÉÑ¡)
ÔØÈë³É¹¦Ê±»Øµ÷º¯Êý(Ö»Óе±ResponseµÄ·µ»Ø״̬ÊÇsuccess²ÅÊǵ÷Óø÷½·¨)¡
Ïà¹ØÎĵµ£º
ºÜ¶àÅóÓÑÎÊÎÒÈçºÎʵÏÖÎÞË¢ÐÂÉÏ´«Í¼Æ¬,ÕâÀïСºÚ¸ø´ó¼ÒÕÒÁËһƪ¹ØÓÚÎÞË¢ÐÂʵÏÖͼƬÉÏ´«µÄÎÄÕÂ,Ï£Íû¶Ô´ó¼ÒÓаïÖú.
±¾ÎÄ¿Í·þ¶ËʹÓõÄÊÇajax.netÒì²½ÉÏ´«Îļþ
1.ÔÚ
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utilit ......
JSON²å¼þÌṩÁËÒ»ÖÖÃûΪjsonµÄResultType£¬Ò»µ©ÎªÄ³¸öActionÖ¸¶¨ÁËÒ»¸öÀàÐÍΪjsonµÄResult£¬Ôò¸ÃResultÎÞÐèÓ³Éäµ½ÈκÎÊÓͼ×ÊÔ´¡£ÒòΪJSON²å¼þ»á¸ºÔð½«ActionÀïµÄ״̬ÐÅÏ¢ÐòÁл¯³ÉJSON¸ñʽµÄÊý¾Ý£¬²¢½«¸ÃÊý¾Ý·µ»Ø¸ø¿Í»§¶ËÒ³ÃæµÄJavaScript¡£
¡¡¡¡¼òµ¥µØ˵£¬JSON²å¼þÔÊÐíÎÒÃÇÔÚJavaScriptÖÐÒì²½µ÷ÓÃAction£¬¶øÇÒAction²»ÔÙÐè ......
Ò».¹¤¾ßÏÂÔØ
1.ASPAJAXExtSetup.msi
http://download.microsoft.com/download/5/4/6/5462bcbd-e738-45fa-84ca-fa02b0c4e1c2/ASPAJAXExtSetup.msi
2.ASPAJAXSourceCode.msi
http://download.microsoft.com/download/6/d/6/6d6c7c47-b9ff-4934-bb03-8a45b8418d35/ASPAJAXSourceCode.msi
3.AjaxControlToolkit
http://ww ......
1´´½¨Á½ÕÅÒ³Ãæ Reg.aspx¡¢CallServer.aspx¡£
ÔÚReg.aspxÒ³ÃæµÄhtmlÖзŠһ¸ö²ãºÍÒ»¸öÎı¾¿ò
<div id="aa">
<asp:TextBox id="txtuser" runat="server" Width="136px"></asp:TextBox>
</div>
<span id="errInfo">ÇëÊäÈëÓû§Ãû</span>
ÔÚReg.aspxÒ³ÃæÖÐдjavascript
¶¨Òå¶þ¸ö±äÁ¿ ......
ajaxÇëÇó²»·µ»Øhtml´úÂëµÄÈýÖÖ·½Ê½
ajaxÇëÇó´úÂ룺
function ajaxSend() {
$.ajax({
url: “Test_Ajax.aspx”,
type: “post”,
data: { name: “ajax” },//Èç¹ûÇëÇóµÄ×ÔÉíÒ³Ã棬ΪÁËÔÚºǫ́ÅжÏÊDz»ÊÇajaxÇëÇó
error: function(xhr, textStatus, errorThown) {
alert(errorThown) ......