【问题标题】:Displaying value in textbox for to edit using ajax and php在文本框中显示值以使用 ajax 和 php 进行编辑
【发布时间】:2017-06-26 22:57:36
【问题描述】:

editModal.php

  <div id="edit-modal" class="modal fade" tabindex="-1" role="dialog" aria-    labelledby="myModalLabel" aria-hidden="true" style="display: none;">
         <div class="modal-dialog"> 
              <div class="modal-content"> 

                   <div class="modal-header"> 
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
                        <h4 class="modal-title">
                            <i class="glyphicon glyphicon-edit"></i> Edit Profile
                        </h4> 
                   </div> 
                   <div class="modal-body"> 

                       <div id="modal-loader" style="display: none; text-align: center;">
                        </div>

                       <div id="dynamic-content">

                       <div class="row"> 
                            <div class="col-md-12"> 

                            <div class="table-responsive">

                         <table class="table table-bordered">
                            <tr>
                            <th>First Name</th>
                            <td id="txt_first">
                          <input  id="result_table" type="text" class="form-control" name="Firstname" ng-model="name">
                          </td>
                          </tr>

                            <tr>
                            <th>Middle Name</th>
                            <td id="txt_middle" > </td>
                            </tr>

                            <tr>
                          <th>Last Name</th>
                          <td id="txt_last"></td>
                            </tr>

                            <tr>
                            <th>Email Add</th>
                            <td id="txt_emailadd"></td>
                            </tr>

                            <tr>
                            <th>Contact Number</th>
                            <td id="txt_cnumber"></td>
                            </tr>


                            </table>

                            </div>

                            </div> 
                      </div>

                      </div> 

                    </div> 
                    <div class="modal-footer"> 
                          <button type="submit" value="send" name="submit" class="btn btn-primary">Save Changes</button>  
                          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  
                    </div> 

             </div> 
          </div>
   </div><!-- /.modal -->    

</div>

  $(document).on('click', '#getUser', function(e){

                  e.preventDefault();

                  var uid = $(this).data('id'); // get id of clicked row

                  $('#dynamic-content').hide(); // hide dive for loader
                  $('#modal-loader').show();  // load ajax loader

                  $.ajax({
                    url: '../model/editUser.php',
                    type: 'POST',
                    data: 'id='+uid,
                    dataType: 'json'
                  })
                  .done(function(data){
                    console.log(data);
                    $('#dynamic-content').hide(); // hide dynamic div
                    $('#dynamic-content').show(); // show dynamic div
                    $('#txt_first').html(data.First_Name);  
                    $('#txt_middle').html(data.Middle_Name);
                    $('#txt_last').html(data.Last_Name);
                    $('#txt_emailadd').html(data.Email_Add);
                    $('#txt_cnumber').html(data.Contact_Number);
                    $('#modal-loader').hide();    // hide ajax loader
                  })
                  .fail(function(){
                    $('.modal-body').html('<i class="glyphicon glyphicon-info-sign"></i> Something went wrong, Please try again...');
                  });

                });

              });

              </script>

我想显示 $('#txt_first').html(data.First_Name); 的值在输入 type="text" value = "php echo $firstName" 但似乎我做错了。我是否可以将表格和脚本包含在 ;段?

【问题讨论】:

    标签: php ajax database input edit


    【解决方案1】:

    它是输入字段,所以你需要用'value'而不是'html'来做。试试这个:

     $('#txt_first').val(data.First_Name);
    

    【讨论】:

    • 谢谢!真的很感激你回答我的问题并帮助我
    【解决方案2】:

    创建演示以显示 data.First_Name 输入类型="text"

    $('#result_table').val("test");  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table class="table table-bordered">
                                <tr>
                                <th>First Name</th>
                                <td id="txt_first">
                              <input  id="result_table" type="text" class="form-control" name="Firstname" ng-model="name">
                              </td>
                              </tr>
    
                                <tr>
                                <th>Middle Name</th>
                                <td id="txt_middle" > </td>
                                </tr>
    
                                <tr>
                              <th>Last Name</th>
                              <td id="txt_last"></td>
                                </tr>
    
                                <tr>
                                <th>Email Add</th>
                                <td id="txt_emailadd"></td>
                                </tr>
    
                                <tr>
                                <th>Contact Number</th>
                                <td id="txt_cnumber"></td>
                                </tr>
    
    
                                </table>

    【讨论】:

    • @Java Beginner:这有助于实现你想要的
    猜你喜欢
    • 2017-08-05
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    相关资源
    最近更新 更多