选择不通过ajax追加的值

时间:2016-10-13 10:19:30

标签: javascript jquery ruby-on-rails ajax

我是AJAX的新手。我在RoR中有一个Invoice表单,其中包含客户,产品和服务字段。当我从select选项中选择客户名称时,它应该动态地从客户表单中填写几个字段。同样,产品形式的产品和服务形式的服务。



$("#customer_name").on('change', function() {
  $(this).valid();
  var customer_name = $('#customer_name').val();

  if ($('#customer_name').val() == 'Add New') {
    $.ajax({
      type: "GET",
      url: '/customer_details/new',
      success: function(result) {
        $('#myModal').modal('show');
        $('#myModal .modal-body').html(result.html);
      },
      complete: function(result) {
        popup.customerDetail();
      }
    });
  } else {
    $.ajax({
      type: "POST",
      url: '/invoices/dropdown',
      data: {
        customer_name: customer_name
      },
      success: function(result) {
        $(".append-customer-details").html(result.html);
        $('.selectpicker').selectpicker('refresh');
      }
    });
  }
});

= fields_for Invoice.new do |f|
  = f.label :customer_detail_id,"Customer Name"
  = f.select(:customer_detail_id, CustomerDetail.collect_customer_name,{},{prompt: "Select customer", class: "selectpicker form-control", id: "customer_name", "data-live-search": "true"})




问题是一旦页面被提交或刷新后选择选项没有显示。所以依赖于选择选项的字段也无法显示。我不知道如何将选择值传递给JS.can有人请帮助我。在此先感谢!!

0 个答案:

没有答案