weixin_42242748 2008-08-19 21:06
浏览 207
已采纳

如何将SELECT改用LINK_TO

[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。

  • 写回答

1条回答 默认 最新

  • superxielei 2008-08-20 20:11
    关注

    不是很清楚你想做什么,如果你是希望使用超连接的方式实现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: Refresh
    link_to_remote(image_tag("refresh"), :update => "emails",
    :url => { :action => "list_emails" })
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?