Topic: Ajax on rails doubt respond_to format.js not working as expected

Hi all.

I'm trying to get Ajax working but without success, this is my scenario.

A bike belongs_to a seller.

So in my bike form I have a jquery autocomplete combobox which shows all the names of possible sellers. When the user selects a seller, other div (rendered in a partial) needs to be updated with seller details.

In event from autocomplete combobox I do

$.ajax({
type: "GET",
url: "/bikes/seller_selected/" + ui.item.option['value'],
success: function(data){
    document.getElementById('selected_contact_name').innerHTML = "teste = " + data;
}
});

And the controllers action:

def seller_selected
  seller_id = params[:seller_id]
  @selected_contact = Contact.find(seller_id)
  logger.debug("DEBUG - #{seller_id} - #{@selected_contact}")

  respond_to do |format|
    format.js {
      render :partial => "seller_details", :locals => {:selected_contact => @selected_contact}
    }
  end
  
end

My view looks like:

 <div class="contact_details_wrapper" style="margin-left: 10px; float: left;">
   <%= render :partial => "seller_details", :locals => {:selected_contact => @selected_contact} %>
 </div>

And the partial named _seller_details.html.erb in the same dir as _form is:

<div class="sb_form">
  <table>
    <tr>
      <td>Nome: </td>
      <td id="selected_contact_name"><%= @selected_contact.name if @selected_contact != nil %></td>
    </tr>
  </table>
</div>

I'm running it on chrome and I can see the answer from the server arriving with the expected content, but the page is not updated.

What am I doing wrong?

Re: Ajax on rails doubt respond_to format.js not working as expected

whrere dose your params[:seller_id] come from?

may should write like this

$.ajax({
type: "GET",
url: "localhost:3000/bikes/seller_selected" 
data:{:seller_id => ui.item.option['value']},
success: function(data){
    document.getElementById('selected_contact_name').innerHTML = "teste = " + data;
}
});
i am a rails rookie