我应该(以及如何)使用模态引导程序运行php脚本吗?

时间:2016-03-13 11:07:07

标签: php modal-dialog

我已经创建了一个phpscript - 计算器 How to optimize this short script in php - salary calc 它正在发挥作用。 现在我想做这样的事情。我的网页上有一个人点击按钮,计算器就像小窗口一样打开,他使用计算器,当他完成时,用计算器关闭窗口并再次在网页上。据我了解,我应该使用bootstrap模式这样做:http://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_modal_sm&stacked=h 我理解对吗? 我应该如何将我的phpscript链接到这个模态?

谢谢你的提示?

1 个答案:

答案 0 :(得分:2)

你需要的是一个带有模态事件监听器的Ajax方法,

模态HTML

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Small Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog modal-sm">
      <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
              <div id="showcal"></div>
            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
     </div>
    </div>
</div>

使用Ajax方法的B.S模态事件监听器

$(document).ready(function(){
    $('#myModal').on('shown.bs.modal', function () {
        $.ajax({
            type: 'GET',
            url: "calculator.php", //this file has the calculator function code
            success:function(data){
             $('#showcal').html(data);
            }
        });
     });
});

并在最后calculator.php

<?php
       //Here comes the calculator code
?>

Lemme知道它是否有效,如果没有,它会使它发挥作用。