douzhao7014 2016-12-31 15:35
浏览 56
已采纳

在HTML中,如何检索存储在jQuery的Ajax中读取的php变量中的数据?

I have written a website (in A.php) with a few tabs, each of which, when clicked on, retrieves multiple pictures data from another php file (= B.php) using jQuery's ajax and displays them. Those pictures are objects of a class (declared in C.php) and each picture has unique name, date when it was taken, and place where it was taken. They are all written in PHP and stored in php variables. Initially, when the data are asynchronously retrieved and the pictures are displayed, they only show the pictures and the name of them, but not the date and place. I want to make each picture show, using modal, the date and place only when they are clicked on.

I got the modal part working, but it is currently blank as I am not sure how to approach this problem and show the date and place for each photo.

Below is part of A.php where modal is, in which I want to show date and place of each photo:

<div class="modal">
    <!-- Close modal process here (omitted)-->
    <div class="date-and-place">
        <?php
           /*I am not sure what to write in here*/
        ?>
    </div>
</div>

Below is B.php:

/*This is the data displayed on the screen after the tab is clicked on, 
  using ajax call from A.php
  This will only show the pictures and the name*/
<?php
    require_once("C.php");
?>
<div class="pictureData">
    <!--loop through an array containing all picture objects-->
    <?php foreach($pictures as $picture): ?>
        <img class="picture"><?php echo $picture->getPicture() ?>
        <h3 class="pictureName"><?php echo $picture->getName() ?></h3>
    <?php endforeach ?>
</div>

And finally C.php:

/*This file only has class and object definitions*/
<?php
    class Pics{
        private $name;
        private $imgURL;
        private $date;
        private $place;
    }
    /*There is constructor here, and each object is given name,              
      imgURL, date and place when created(omitted)*/
    /*and there is getter functions for each as well (omitted)*/
    /*Store each object data in an array*/
    $pictures = array($object1, $object2, ....);
?>

How could you possibly show the specific photo's date and place information (only show the date and place of the picture clicked on)? Any help would be greatly appreciated and thanks in advance!

  • 写回答

1条回答 默认 最新

  • dougu5886 2016-12-31 15:49
    关注

    I'd take an entirely different approach:

    1. send complete image data using json_encode($pictures)
    2. client-side: store image array; show images
    3. on click, modal simply reads additional data from JS array

    This also separates content from presentation, since B.php no longer sends HTML.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab