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 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决