Rails ajax µÄÁª¶¯µÄÏÂÀ¿ò
# app\controllers\examples_controller.rb
ruby ´úÂë
class ExamplesController < ApplicationController
def ajax_select
@items = %w{AA BB}
end
def get_sub_items
if params[:item] == "AA"
@sub_items = %w{AA1 AA2}
else
@sub_items = %w{BB1 BB2}
end
render :partial => "select"
end
end
# app\views\examples\ajax_select.rhtml
xml ´úÂë
<%= javascript_include_tag :defaults %>
<h1>Examples#ajax_select</h1>
<p>Find me in app/views/examples/ajax_select.rhtml</p>
<%= select :obj, :att, @items, {}, :onchange => remote_function(:update => "sub_items",
:method => "get",
:with => "'item=' + value",
:url => { :controller => :examples, :action => :get_sub_items})
%>
<div id="sub_items">
<select></select>
</div>
#app\views\examples\_select.rhtml
ruby ´úÂë
<%= select(:obj, :item
Ïà¹ØÎĵµ£º
×î½üÍøÉÏÌáµÄºÜ¶àµÄÒ»¸öиÅÄî¾ÍÊÇ AJAX ÁË, ÄÇô, AJAX ÊÇÊ²Ã´ÄØ? ÒÔÏÂÄÚÈÝÒýÓÃÍøÉÏ×ÊÁÏ:
AJAXÈ«³ÆÎª“Asynchronous JavaScript and XML”£¨Òì²½JavaScriptºÍXML£©£¬ÊÇÖ¸Ò»ÖÖ´´½¨½»»¥Ê½ÍøÒ³Ó¦ÓõÄÍøÒ³¿ª·¢¼¼Êõ¡£ËüÓлúµØ°üº¬ÁËÒÔϼ¸ÖÖ¼¼Êõ£º
Ajax£¨Asynchronous JavaScript + XML£©µÄ¶¨Òå
»ùÓÚ web±ê×¼£¨sta ......
ÓкܾÃÒ»¶Îʱ¼äÎÒµÄBLOGÉÏûÓгöÏÖAJAXÏà¹ØÑ¶Ï¢ÁË£¬Ö÷Òªµ±È»ÊÇÒòΪ¾ø´ó²¿·ÖµÄÖØÐͼ·Åµ½ÁËSilverlightÉíÉÏ(¿ÉÔ¤ÆÚµÄδÀ´Ó¦¸ÃÒ²»áÊÇÈç´Ë)¡£
µ«ÓÉÓÚ¹¤×÷ÉϵÄÐèÒª£¬×î½ü»¹ÊÇ»ØÍ·¿´ÁËһϼ´½«ÍƳöµÄASP.NET Ajax Library...£¬Ë³±ãÕÒÁËÒ»ÏÂÍøÂçÉϵÄѶϢ£¬¿´Õâ¸öÌ¬ÊÆÎÒ²ÂÏëÓ¦¸Ã²»ÉÙASP.NET¿ª·¢ÈËÔ±ºöÂÔµôÁËÕâ¸öÆäʵÒѾbet ......
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) ......
×î½üÔÚÓÃAjax×öµÇ¼´°¿Ú£¬µ«ÊÇlogoutµÄʱºòÐèÒª¶Ôsession½øÐд¦Àí¡£ÓõÄÊÇsession.removeAttribute()º¯Êý½øÐÐlogout¡£µ«ÊÇ£¬ÊÂʵ֤Ã÷£¬ÔÚlogoutÒÔºó£¬ÔٴεǼµÄʱºò£¬²¢²»Äܵǽ³É¹¦£¬Ñ¹¸ù²»»á½øÈëactionÖ´ÐÐÏàÓ¦µÄ·½·¨£¨hqlÓï¾äҲûÓÐÖ´ÐУ©¡£
Ϊ´Ë£¬¾Ý˵ÓÐÁ½ÖÖ·½·¨½ ......