2016-12-15 65 views
0

对于那些熟悉的bootbox,您可能可以执行此操作。在Bootbox消息字段中获取PHP文件

我想要做的是获取一个模态框内的PHP文件。以下是代码:

$('#testBootBox').click(function(e){ 
    bootbox.dialog({ 
     title: "Test", 
     message: pageInsertion(); 
    }); 
}); 

function pageInsertion(){ 
    var form = "<?php include('TestPage.php'); ?>"; 
    return form; 
} 

我该如何去做这件事?

+1

你可以做到这一点与阿贾克斯......你叫调用服务器端脚本'TestPage.php' Ajax的功能,然后呈现在客户端输出indise您bootbox对话框 – Hackerman

+0

你可以做一些解释代码或在网上我可以得到一个类似的例子? –

+0

我可以给你一个完整的答案,但首先,如果你运行你的'TestPage.php'它运行良好,没有任何错误? – Hackerman

回答

0

您可以轻松地完成,以使您的服务器响应客户使用Ajax该任务:

$(function(){ 
    $('#testBootBox').click(function(e){ 
     $.ajax({ 
      url:'testpage.php', 
      type:'get' 
     }).done(function(response){ 
     bootbox.dialog({ 
      title: "Test", 
      message: response; 
     }); 
     }); 
    }); 
}): 
0

只是显示这个表单中隐藏的div。像这样:

<div id="hiddendiv" style="display: none;"><?php include('TestPage.php'); ?></div> 
<script> 
    $('#testBootBox').click(function(e){ 
     bootbox.dialog({ 
      title: "Test", 
      message: $('#hiddendiv').html() 
     }); 
    }); 
</script> 

或者你可以把HTML直接:

<script> 
    <?php 
     ob_start(); 
     ob_implicit_flush(false); 
     require include('TestPage.php'); 
     $form = json_encode(ob_get_clean()); 
    ?> 
    $('#testBootBox').click(function(e){ 
     bootbox.dialog({ 
      title: "Test", 
      message: <?php echo $form; ?> 
     }); 
    }); 
</script> 

或者使用AJAX像以前的答案。

0

Hackerman感谢您的帮助。你只有一个错误......分号并不是在响应之后。大声笑 。以下是完整的答案。

$(document).ready(function(){ 



$('#testBootBox').click(function(e){ 
     $.ajax({ 
      url:'TestPage.php', 
      type:'get' 
     }).done(function(response){ 
      bootbox.dialog({ 
      title: "Test", 
      message: response 
      }); 
     }); 
    }); 






    });