Javascript 将php文件(html w/php)的内容附加到div

Javascript 将php文件(html w/php)的内容附加到div,javascript,jquery,ajax,Javascript,Jquery,Ajax,如何将php文件的内容(html和php的混合)附加到现有的div中 我定义了这个div,它加载三个不同的php文件。但这非常慢,因为每个php都使用http检索许多项。我希望有第一个php,然后异步加载其他php。我尝试了$.get(),但它没有加载php内容 这是分区 <div id="readings"> <?php require("readenglish.php"); ?> <!-- ?php require("readfrench.ph

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

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

这是分区

<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>

$(文档).ready(函数(){
$.get(“readfrench.php”,函数(数据){
$(“#读数”)。附加(数据);
},'html');
$.get(“readspanish.php”,函数(数据){
$(“#读数”)。附加(数据);
},'html');
});
下面是一个示例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()?有没有其他方法可以做到这一点?

您的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>

一读

代码确实有效。tabber插件似乎无法添加到jscript中,它必须首先位于页面上。如果是在javascript中添加的,则不会绘制元素。

听起来您已经在通过ajax加载内容并将其填充到元素中了。那么问题出在哪里?@user823527验证您的PHP代码。好吗@Tejs更新了问题以显示我想要什么。ajax不发送内容。如果我将其直接放在
中,则会加载相同的内容。我想让$.get()工作,或者用另一种方法做同样的工作,即异步调用.php。@Tejs@ngen似乎是
$.get()
正在从php文件检索数据。但是对.append()的调用似乎没有将其添加到元素中。在使用
load
时,不需要在回调中追加标记。这就是使用load的全部意义。我错过了。但我认为他有一些PHP问题。我正在调查此事。:)php运行良好。我的问题是如何不将所有内容都放在
中,而是使用ajax加载它。另外,我只为php文件调用一次
curl\u init()
curl\u close()
。在此期间,我多次调用
curl\u exec
。错了吗?@user823527您使用的脚本将获取内容并将其添加到#readings的现有内容中。就像你想要的。我不明白哪一部分不适合你?。您能说得更清楚一点吗?@user823527尝试在加载的页面中的div上不使用特定的readf和tabbertab类来执行相同的操作