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
Ïà¹ØÎĵµ£º
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
¶¨Òå¶þ¸ö±äÁ¿ ......
<!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/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>¼òµ¥µÄÓ¦ÓÃXMLHt ......
×òÌì¿´ÁËÆª²»ÊǺÜÑϽ÷µÄ²©ÎÄ¡¶Ò»¸öËãÃüС͵³ÌÐòµÄµ®Éú¡·£¬ÀïÃæÐ´ÁËÒ»¸öͨ¹ýAJAX͵ÇÔ±ðÈËÍøÕ¾Ëã·¨µÄ·½·¨¡£Êµ¼ùÁËһϸù±¾²»ÐУ¬AJAXËÆºõ²»ÄÜ¿çÓò¡£
ºóÀ´ÎÒÏëÁËһЩ½â¾ö·½·¨£¬ÖÕÓÚ¿çÓò³É¹¦¡£ÏÖÔÚ¹«²¼Ò»Ï·½·¨¡£
ÈÎÎñ£ºÔÚ×Ô¼ºÍøÕ¾×ö¸ö±íµ¥£¬Ïò¡ ......
oad()·½·¨
load( url [,data] [,callback]) dataÊÇObjectÀàÐÍ£¬·¢ËÍÖÁ·þÎñÆ÷µÄkey/valueÊý¾Ý
Àý£º
$(function(){
$("#send").click(function(){
$("#resText").load("test.html ......