.modal('显示&#39); - 没有显示模态

时间:2018-03-12 08:14:13

标签: jquery ajax modal-dialog

我试图显示一个模式,它将显示带有我显示的表格中的值的文本框。即时通讯使用此代码触发模态:$('#updatemodal').modal('show');但它无效。

这是用于将表格内容传输到模态并显示模态的脚本:

<script>
    $(document).on('click','.edit_data',function(){  
       var awardee_id = $(this).attr("uawardeeid");  
       $.ajax({  
            url:"fetchawardees.php",  
            method:"POST",  
            data:{awardee_id:awardee_id},  
            dataType:"json",  
            success:function(data){  
                 $('#updatemodal').modal('show');
                 $('#uawardeeid').val(data.awardee_id);   
                 $('#uawardeename').val(data.awardee_name);   
                 $('#uawardeeaddress').val(data.awardee_address);   
                 $('#uawardeecontact').val(data.awardee_contact_info);   
                 $('#uaward').val(data.award_id);   
                 $('#ucategory').val(data.category_id);   
                 $('#uregion').val(data.region_id);   
                 $('#uprovince').val(data.province_id);   
                 $('#uimage').val(data.awardee_img);   

            }  
       });  
  }); 

这是模态内容的代码:

            <form class="form-horizontal" id="updateform" name="updateform" action="phpawardee.php" method="POST" enctype="multipart/form-data">
        <div class="modal fade in" tabindex="" role="dialog" aria-hidden="false"  name="updatemodal" id="updatemodal">   
            <div class="modal-dialog modal-lg" >
                <div class="modal-content" >
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h4 class="modal-title">Edit Awardee</h4>
                    </div>
        <div class="modal-body">  

                <div class="panel-body">
                          <input id="uawardeeid" name="uawardeeid" type="text" class="form-control">
                                <fieldset>
                                    <!-- Name input--> 
                                    <div class="form-group">
                                        <label class="col-md-3 control-label" for="name">Awardee Name</label>
                                        <div class="col-md-9">
                                            <input id="uawardeename" name="uawardeename" type="text" placeholder="" class="form-control"></div>
                                    </div>
                                    <!-- Address body -->
                                    <div class="form-group">
                                        <label class="col-md-3 control-label" for="message">Address</label>
                                        <div class="col-md-9">
                                            <textarea class="form-control resize_vertical" id="uawardeeaddress" name="uawardeeaddress" placeholder="" rows="4"></textarea>
                                        </div>
                                    </div>
                                    <!-- Contact info input-->
                                    <div class="form-group">
                                        <label class="col-md-3 control-label" for="name">Contact Info.</label>
                                        <div class="col-md-9">
                                            <input id="uawardeecontact" name="uawardeecontact" type="number" placeholder="" class="form-control" ></div>
                                    </div>
                                    <!-- Level of Award input-->
                                    <div class="form-group">
                                        <label class="col-md-3 control-label" for="email">Level of Award</label>
                                        <div class="col-md-9">
                                            <select id="uaward" name="uaward" class="form-control">
                                                <option>Select</option>
                                                    <?php
                                                        $res=mysqli_query($db, "select * from tbl_award_level");
                                                        while($row=mysqli_fetch_array($res))
                                                        {
                                                    ?>
                                                 <option value="<?php echo $row["award_id"]?>"><?php echo $row["award_name"]; ?></option>
                                                    <?php
                                                        }
                                                    ?>
                                            </select></div>
                                    </div>
                                    <!-- Store Category-->
                                    <div class="form-group">
                                        <label class="col-md-3 control-label" for="email">Store Category</label>
                                        <div class="col-md-9">
                                            <select id="ucategory" name="ucategory" class="form-control">
                                                <option>Select</option>
                                                    <?php
                                                       $res=mysqli_query($db, "select * from tbl_store_category");
                                                     while($row=mysqli_fetch_array($res))
                                                       {
                                                    ?>
                                                <option value="<?php echo $row["category_id"]?>">
                                                    <?php echo $row["category_name"]; ?></option>
                                                    <?php
                                                            }
                                                    ?>
                                            </select></div>
                                    </div>
                                    <!--Region-->
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">Region</label>
                                        <div class="col-md-9">
                                            <select id="uregion" name="uregion" class="form-control" onChange="change_region2()">
                                                <option>Select</option>
                                                    <?php
                                                        $res=mysqli_query($db, "select * from tbl_region");
                                                        while($row=mysqli_fetch_array($res))
                                                            {
                                                    ?>
                                                <option value="<?php echo $row["region_id"]?>">
                                                    <?php echo $row["region_name"]; ?></option>
                                                    <?php
                                                            }
                                                    ?>
                                            </select></div>
                                    </div>
                                     <!-- Province-->
                                    <div class="form-group">
                                        <label class="col-md-3 control-label">Province</label>
                                        <div class="col-md-9">
                                            <select id="uprovince" name="uprovince" class="form-control">
                                                <option>Select</option>
                                                <option></option>

                                            </select></div>
                                    </div>
                                    <!--File Upload-->
                                    <div class="form-group">
                                        <label class="col-md-3 control-label" for="name">Choose Photo</label>
                                        <div class="col-md-9">
                                            <div class="fileinput fileinput-new input-group" data-provides="fileinput">
                                                <div class="form-control" data-trigger="fileinput" >
                                                    <i class="glyphicon glyphicon-file fileinput-exists"></i>
                                                    <span class="fileinput-filename"></span>
                                                </div>
                                                <span class="input-group-addon btn btn-default btn-file">
                                                    <span class="fileinput-new">Select file</span>
                                                    <span class="fileinput-exists">Change</span>
                                                    <input type="file" name="uimage" ></span>
                                                <a href="#" class="input-group-addon btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                <button type="button" data-dismiss="modal" class="btn btn-default">Close</button>

                                <button type="submit" class="btn btn-primary" id="updatebutton" name="updatebutton">Update</button>
                            </div>
                                    <!-- Form actions -->
                                </fieldset>

                        </div>
                            </div>  
                        </div>
                    </div>
                </div>
            </form>

这是按钮的代码我应该点击以显示模态:

<a name="edit" value="Edit" data-toggle="modal" id="<?php echo $awardee["awardee_id"]; ?>" class="btn btn-md btn-primary edit_data" >Edit</a>

2 个答案:

答案 0 :(得分:0)

您的代码中存在错误。

你已经用过了

var awardee_id = $(this).attr("uawardeeid");

但是在你的按钮中你没有提到“uawardeeid”。

<a name="edit" value="Edit" data-toggle="modal" id="<?php echo $awardee["awardee_id"]; ?>" class="btn btn-md btn-primary edit_data" >Edit</a>

在你的jQuery替换

var awardee_id = $(this).attr("id");

希望它有所帮助。

感谢。

答案 1 :(得分:0)

打开开发人员工具(F12)并转到“网络”选项卡。 当你按下按钮时,你应该看到你发的POST,并且可以检查你发送的参数以及你的AJAX得到的响应。

检查POST是否正常。 它可能是你的PHP控制器中的一个错误&quot; fetchawardees.php&#39;。