[code] function loadItemByCatalog(id)
{
var src = $('category');
var selected = src.selectedIndex;
$('cat').innerHTML= src.options[selected].innerHTML;
//下面是請求的地址
var url = "/auctioning/list_items" ;
var params = "kind=" + id;
//創建一個Ajax.Request對象,對應於發送一次Ajax請求
var myAjax = new Ajax.Request(
url,
{
//請求方式:POST
method:'post',
//設置請求參數
parameters: params,
//指定回調函數
onComplete: showList,
//是否異步發送請求
asynchronous:true
});
}
<select id="category" name="category" size="8" onChange="loadItemByCatalog(this.value);">
<%= options_from_collection_for_select(@categories, "id", "cname") %>
</select>[/code]
[b]问题补充:[/b]
想要用超链接的方式实现ajax提交,可是要如何在link_to_remote中应用loadItemByCatalog。
不是很清楚你想做什么,如果你是希望使用超连接的方式实现ajax提交,可以使用link_to_remote
[code="ruby"]
link_to_remote(name, options = {}, html_options = nil)
[/code]
[code="ruby"]
# Generates: Delete this post
link_to_remote "Delete this post", :update => "posts",
:url => { :action => "destroy", :id => post.id }
# Generates:
link_to_remote(image_tag("refresh"), :update => "emails",
:url => { :action => "list_emails" })
[/code]