Jquery .text() with php foreach

Jquery .text() with php foreach

本文关键字:php foreach with text Jquery      更新时间:2023-09-26

我想在div中动态显示一些内容。这个内容来自于我在php中的一个函数。

我该怎么做呢?

HTML:

 <div class="creativeSecondField">
      <h1 class="secondFieldTitle"></h1>
      <div class="secondFieldContent"></div>
</div>
JQUERY:

$(".creativeSecondField > div.secondFieldContent").text(""+
    <?php
    $info+this.id = $this->sqlCategories+this.id;
    foreach ( $info+this.id as $valuesinfo+this.id )
    {
    echo $valuesinfo+this.id['designation_en'];
    }
    ?>
+"");

首先创建一个php页面,返回像

这样的动态内容

getContent.php

<?php
echo "hello";
?>

之后,在你想用jquery显示动态内容的页面上,像这样做

    <div class="creativeSecondField">
          <h1 class="secondFieldTitle"></h1>
          <div class="secondFieldContent"></div>
    </div>
<script>
$(document).ready(function() {
$(".secondFieldTitle").load("getContent.php");
});
</script>

使用它,谢谢....