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.

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

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备