0

如何将 php 文件(html 和 php 的混合)的内容附加到现有的 div 中?

我定义了这个 div,它加载了三个不同的 php 文件。但这非常慢,因为每个 php 都使用 http 检索许多项目。我想要第一个 php<?php require("readenglish.php"); ?>然后异步加载其他的。我尝试了 $.get() ,但没有加载 php 内容。

这是div。

<div id="readings">

    <?php require("readenglish.php"); ?>
    <!-- ?php require("readfrench.php"); ? --> <!-- EDITED OUT DON'T WANT THIS -->
    <!-- ?php require("readspanish.php"); ? --> <!--  -->

</div>

这是加载 php 文件的脚本。

<!--  EDIT  WANT THIS INSTEAD OF WHAT IS COMMENTED OUT ABOVE -->
<script>
    $(document).ready(function(){    
    $.get("readfrench.php",function(data){
        $("#readings").append(data);
    },'html');

    $.get("readspanish.php",function(data){
        $("#readings").append(data);
    },'html');    
    });

</script>

这是一个示例 php 文件。

<?php 

    $todayfeast = date("Ymd");

    $ctitlefe = 'http://feed.evangelizo.org/reader.php?date='.$todayfeast.'&type=reading_lt&lang=AM&content=FR';
    $creadfe = 'http://feed.evangelizo.org/reader.php?date='.$todayfeast.'&type=reading&lang=AM&content=FR';

    if ( $curl_exists ) {
        curl_setopt($ch, CURLOPT_URL, $ctitlefe);        
        $titlefe = curl_exec($ch);

        curl_setopt($ch, CURLOPT_URL, $creadfe);      
        $readfe = curl_exec($ch);
    }

?>
    <div id="readf" class="tabbertab">
        <h2>First Reading</h2>

        <div id='titlefe' class='rtitle'>
        <?php echo $titlefe; ?>
        </div>
        <div id='readfe' class='rtext'>
        <?php echo $readfe; ?>
        </div>

    </div>

php 文件将检索到的内容加载到传递给 html 元素的变量中。这些元素必须附加到顶部显示的 div 中。

是否有不同的方式来调用 $.get()?有不同的方法可以做到这一点吗?

4

2 回答 2

0

您的 JScript 工作正常。我唯一想不通的是PHP代码。它是否使用您的代码输出正确的文档?这是我尝试过的代码。它正在工作。

PHP

<?php 

    $todayfeast = date("Ymd");

    $ctitlefe = 'http://feed.evangelizo.org/reader.php?date='.$todayfeast.'&type=reading_lt&lang=AM&content=FR';
    $creadfe = 'http://feed.evangelizo.org/reader.php?date='.$todayfeast.'&type=reading&lang=AM&content=FR';



    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$ctitlefe);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    $titlefe= curl_exec($ch);
    curl_close($ch);

    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$creadfe);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    $readfe= curl_exec($ch);
    curl_close($ch);    


?>
    <div id="readf" class="tabbertab">
        <h2>First Reading</h2>

        <div id='titlefe' class='rtitle'>
        <?php echo $titlefe; ?>
        </div>
        <div id='readfe' class='rtext'>
        <?php echo $readfe; ?>
        </div>

    </div>
于 2012-05-03T20:04:04.500 回答
0

该代码确实有效。好像tabber插件不能在jscript中添加它必须在页面上。如果它是在 javascript 中添加的,则不会绘制该元素。

于 2012-05-03T22:24:28.877 回答