问题描述
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,{ //請求方式:POSTmethod:'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>问题补充:想要用超链接的方式实现ajax提交,可是要如何在link_to_remote中应用loadItemByCatalog。
解决方案
不是很清楚你想做什么,如果你是希望使用超连接的方式实现ajax提交,可以使用link_to_remotelink_to_remote(name, options = {}, html_options = nil) # Generates: <a href="#" onclick="new Ajax.Updater('posts', '/blog/destroy/3', {asynchronous:true, evalScripts:true}); # return false;">Delete this post</a> link_to_remote "Delete this post", :update => "posts", :url => { :action => "destroy", :id => post.id } # Generates: <a href="#" onclick="new Ajax.Updater('emails', '/mail/list_emails', {asynchronous:true, evalScripts:true}); # return false;"><img alt="Refresh" src="/images/refresh.png?" /></a> link_to_remote(image_tag("refresh"), :update => "emails", :url => { :action => "list_emails" })