加载远程表单以使用ajax在引导模式下进行编辑


Load remote form for editing in bootstrap modal using ajax

这就是我正在尝试的:

打开模式:

<a href="" class="label label-important" 
data-toggle="modal" data-target="#editFee" 
data-id="'.$month['fid'].'" title="Edit '.$month['status'].' Fee">Edit</a>';

这是modal dialog:

<div class="modal fade" id="editFee" tabindex="-1" role="dialog"
style="width: 25%" aria-labelledby="myModalLabel" aria-hidden="true">
           <div class="modal-dialog">
              <div class="modal-content">
                 <div class="modal-header">
                   <h4 class="modal-title" id="myModalLabel">Pay Fee</h4>
                 </div>
                 <div class="modal-body">
                    <!--Load remode editfee.php--!>
              </div>
        </div>
    </div>
</div>

这是editfee.php

<?php 
$id=$_GET['id'];
$fee = QueryFee('Feetable', $id);
foreach($fee as $feeForm):
?>
<form>
<input type="text" id="amount" value="<?php echo $feeForm['amount']; ?>">
<input type="text" id="dateFee" value="<?php echo $feeForm['dateFee']; ?>">
<input type="submit" id="submitFee" value="Save Fee">
</form>
<?php endforeach;?>

最后是jquery ajax:

$(document).on("click", ".label", function(e){
        e.preventDefault();
        var id= $("#id").val();
        dataEdit = 'id='+id;
        $.ajax({
            type:'GET',
            data:dataEdit,
            url:'editfee.php',
            success:function(data) {
              $(".modal-body").val(data);             
            }
          });
    });

我使用的是引导模式V2.0.4。上面的代码确实打开了对话框,但没有来自editfee.php的远程数据。请帮助我。

在您的示例中,此代码无法工作:

var id= $("#id").val();

你必须使用这样的东西:

var id = $(this).data('id');

结束日期:

$(".modal-body").html(data);  
$(".modal-body").val(data);

不会起作用,因为模态主体只是一个div而不是一个输入元素。所以我们应该给

$(".modal-body").html(data);

而不是

$(".modal-body").val(data);

.val()属性仅用于输入元素。.html()用于将html内容附加到div中。

并通过获取id属性

$(this).attr("id")

$(this).prop("id")