link_to with jquery params in rails

前端 未结 4 1231
野趣味
野趣味 2020-12-30 11:34

I want to make an in-place search in my rails app.
I used button_to_remote with prototype, but now I\'m using JQuery, so I changed to link_to.
This is my code:

4条回答
  •  不思量自难忘°
    2020-12-30 12:09

    You can try this:
    <%= text_field_tag :address %>
    <%= submit_tag "Search", :id => "search_button" %>

    
    ### Paste following code in your javascript
    
    $("#search_button").live("click", function(){
      $.ajax({
        complete:function(request){},
        data:'address='+ $('#address').val(),
        dataType:'script',
        type:'get',
        url: '[ROUTE TO ACTION]' // in your case, may be '/[CONTROLLER NAME]/geocode' until you define route
      })
    });
    
    
    

提交回复
热议问题