我正在创建图片库,首先,它基本上使用 PHP 从服务器加载图像的缩略图,并将它们的alt属性设置为文件夹的路径,然后,我想要做的是,当用户单击其中一个时图像,它应该从该文件夹加载所有图像,但它没有。我使用 jQuery,这是简化的代码。我只需要将路径分配给 PHP 变量。我尝试了我所知道的一切,但没有奏效。
使用 PHP 发送文件的路径
$(document).ready(function(){
$("html").on("click", ".gcube img", function() {
var $path = $(this).attr('alt');
$.post("TESTLOAD.php", { link: $path} );
});
});
TESTLOAD.php 文件:
<?php
$link = $_POST['link'];
echo $link;
//other stuff that will load images will be here
?>
更新
好的,这是足以理解的缩小代码
发送数据的文件中的代码(TESTPOST.php):
path = "projects/first/pic.jpg";
$.post("TESTLOAD.php", { link: path} );
以及应该接收数据但没有接收数据的代码,或者至少它没有回显任何内容:
$link = $_POST['link'];
echo '<div id="blah"> ' . json_encode(var_dump($_POST)) . '</div>';
//I was hoping that after I $.post("TESTLOAD.php", { link: path} ); it even echoes out something but it really does nothing
如果我只是在 jquery 中使用 post,它没有任何回应,所以我必须再次加载它
$("#output").load("TESTLOAD.php");
但我想如果我再次加载它,变量就不会再保存在那里了。知道有什么问题吗?