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
    
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题