weixin_33705053 2013-11-06 15:48 采纳率: 0%
浏览 5

Ajax在输入字段中提交

I know this may be a common question but I've been searching for a couple hours with no luck, so I figured I'd ask.

How do make a form submit through ajax on an input field change? I have a form where, among other things, a user selects a product from a dropdown, and then I want that product's picture to show immediately through ajax. This is what I have:

<%= f.association :product, collection: @products %>
<div id="prodPicture">...</div>

What I think might be the right way is adding remote: true and the url but I haven't gotten it to work as of yet.

<%= f.association :product, collection: @products, remote: true, url: url_for(controller: 'quotes', action: 'getdata'), type: 'JSON' %>

Is that the correct way to adding an ajax event to a form field change?

Thanks in advance for any help!

  • 写回答

3条回答 默认 最新

  • weixin_33724659 2013-11-06 16:07
    关注

    you bind to the dropdowns change event

    $("#idofdropdown").change(function(){
    var selection = $(this).val() // always gets selected value by default
    $.ajax()//and so forth
    
    });
    
    评论

报告相同问题?