【问题标题】:how to show the values of a product details when editing in a modal using jquery,ajax and laravel使用 jquery、ajax 和 laravel 在模态中编辑时如何显示产品详细信息的值
【发布时间】:2022-07-21 22:43:40
【问题描述】:

我想使用模态更新产品的详细信息,从而将详细信息填充到输入中,并且用户可以更改他们希望的位置。我已经能够获得一些详细信息的价值,但我无法做到获取具有下拉列表和带有单选按钮选择的详细信息的值。我正在使用 jquery ajax 从表中获取数据并在表单中自动填充它。我尝试了各种方法来获取下拉列表的值和单选按钮,但它不起作用。我怎样才能获得值。这是我的 ajax 代码。

 //   show editing modal
$('body').on('click','#editrentalhsedetails',function(){
        var rentalhsedetailsid=$(this).data('id');
        $.ajax({
           url:'{{ url("admin/activerental",'') }}' + '/' + rentalhsedetailsid + '/edit',
           method:'GET',
           processData: false,
           contentType: false,
           success:function(response)
           {
              console.log(response.editrentalhsedetail);
              if (response.status==404)
              {
                 alert(response.message);
              } 
              else if(response.status==200)
              {
                 $('#editrentalhsedetailsmodal').modal('toggle');

                     //am able to get these values very well
                 $('#rentalhouseid').val(response.editrentalhsedetail.id);
                 $('.edit_title').html('Edit details for Rental house');
                 $('#rental_name').val(response.editrentalhsedetail.rental_name);
                 $('#monthly_rent').val(response.editrentalhsedetail.monthly_rent);
                 $('#rental-details').val(response.editrentalhsedetail.rental_details);
                 $('#totalrooms').val(response.editrentalhsedetail.total_rooms);

                      //this one is a dropdown and it doesnt work
                 $(".rentalselectcat").select2();
                 $(".rentalselectcat").val(response.editrentalhsedetail.housecategory.rentalcat_title);

                           //this is the radio button it doesnt check the value i have gotten from the tablr
                 $(".waterbill:checked").val(response.editrentalhsedetail.waterbill);
                 $(".electricitybill:checked").val(response.editrentalhsedetail.electricitybill);


            
              }
           }
        })
    })

这是我的下拉菜单的 html 代码

 <div class="form-group inputdetails col-sm-6">
    <label>Rental category<span class="text-danger inputrequired">*</span></label>
      <select name="rentalhousecategory" class="rentalselectcat form-control text-white bg-dark" required style="width:100%;"> 
        @foreach($allrentalcategories as $category)
           <option value="{{ $category->id }}">{{ $category->rentalcat_title }}</option>
         @endforeach  
      </select>
   </div>

这是复选框的html代码

<div class="row section-groups">
   <div class="form-group inputdetails col-sm-6" style="text-align: left">
       <label>Water Bill<span class="text-danger inputrequired">*</span></label>
         <div class="col-sm-10">
            <label class="radio-inline">
            <input type="radio" name="waterbill" checked id="inlineRadio1" class="waterbill">Tenant Pays the Bill 
            </label>
            <label class="radio-inline">
               <input type="radio" name="waterbill" checked id="inlineRadio2" class="waterbill"> Rent Inclusive
            </label>
          </div>
        </div>

    <div class="form-group inputdetails col-sm-6" style="text-align: left">
       <label>Electricity Bill<span class="text-danger inputrequired">*</span></label>
       <div class="col-sm-10">
          <label class="radio-inline">
            <input type="radio" name="electricitybill" class="electricitybill" id="inlineRadio1">Tenant Pays the Bill 
          </label>                                 
          <label class="radio-inline">
              <input type="radio" name="electricitybill" class="electricitybill" id="inlineRadio2"> Rent Inclusive
           </label>
         </div>
       </div>
     </div>

我该如何解决这个问题。

【问题讨论】:

    标签: jquery ajax laravel


    【解决方案1】:

    试一试,因为我不确定这是否正确。

    $('#select_id').val('option_val').change();

    【讨论】:

      猜你喜欢
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多