我正在尝试打开模式时调用数据,但它仅用于第一个用户不适合他人首先,我将单击a href链接,然后将打开包含一些输入字段的模式,在这些输入字段中,用户将能够看到他想看到的人的现有数据。
@foreach($jan as $j) <tr> <td><a href="#" class="btn btn-sm btn-dark investor-edit" data-id="{{ $j->id }}" data-toggle="modal" data-target="#myModal" id="inbox-modal">Edit</a></td> </tr> @endforeach <div class="modal bd-example-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModal" aria-hidden="true"> <div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> <div class="modal-header"> {{-- <h5 class="modal-title float-left" id="exampleModalLabel">The subject of the mail will be displayed here</h5> --}} <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true"><i class="fa fa-times-circle"></i></span> </button> </div> <div class="modal-body"> <div class="small"> <div class="form-row form-group"> <label class="col-md-5"> <h5>Investor Name <span class="form-required">*</span></h5> </label> <div class="col-md-7"> <input type="text" placeholder="Enter Investor Name" class="form-control" id="investor_name" name="email" required> </div> </div> <div class="form-row form-group"> <label class="col-md-5"> <h5>Investor Mobile Number <span class="form-required">*</span></h5> </label> <div class="col-md-7"> <input type="text" placeholder="Enter Investor Mobile Number" class="form-control" id="investor_mobile" name="email" required> </div> </div> <div class="form-row form-group"> <label class="col-md-5"> <h5>Date Of Birth <span class="form-required">*</span></h5> </label> <div class="col-md-7"> <input type="date" placeholder="Enter Date Of Birth " class="form-control" id="dob" name="email" required> </div> </div> <div class="form-row form-group"> <label class="col-md-5"> <h5>Investor Marriage Anniversary <span class="form-required">*</span></h5> </label> <div class="col-md-7"> <input type="date" placeholder="Enter Marriage Anniversary Date " class="form-control" id="marriage_ann" name="email" required> </div> <input type="submit" class="btn btn-block btn-danger" name="submit" id="submit" value="Save"> </div> </div> <div class="col-xs-12 mt-3 small"> <p id="message-body"></p> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button> </div> </div> </div> </div> <script type="text/javascript"> $(document).ready(function () { $('#inbox-modal').on('click', function (e) { var id = $(this).data("id"); $.ajax ({ url: '{{ route('get-investors-data') }}', type: 'GET', data: { 'id': id, }, success: function (response) { $('#investor_name').val(response.user_name); $('#dob').val(response.date_of_birth); $('#investor_mobile').val(response.phone_no); $('#marriage_ann').val(response.anniversary) } }); }); }); </script>
数据仅用于模态内的第一个用户,我无法找出错误
任何帮助将不胜感激
我试图在打开模式时调用数据,但它仅针对第一个用户而不是其他用户。首先,我单击a href链接,然后它将打开包含某些输入的模式...]]
您的Jquery选择器不起作用,因为您正在寻找一个不唯一的ID。使用类代替:
<td><a href="#" class="btn btn-sm btn-dark investor-edit inbox-modal" data-id="{{ $j->id }}" data-toggle="modal"
data-target="#myModal" id="">Edit</a></td>