如何将变量 ($member_id
) 传递到目标 php 页面(成员(member)资料详情查询)?
///-----
echo '<div id="show_profile_box">Show Member Profile details
//MySQL Query to display member profile details</div>
<div id="display_member_id"><a href="show_profile.php"?member_id=$member_id">Display Member id</a></div>';
echo '<script>
$("#show_profile_box").hide(100);
$("#display_member_id").click(function () {
$("#show_profile_box").show(500);
});
</script>';
谢谢。如果您需要更多信息,请告诉我。
* 整个想法是显示/显示选定的成员(member)个人资料详细信息。 *
最佳答案
您正在使用单引号。单引号不解析 PHP 变量。从 PHP 输出多行 HTML 时,请使用heredoc:
echo <<< END_OF_HTML
<div id="show_profile_box">Show Member Profile details
<!--MySQL Query to display member profile details -->
</div>
<div id="display_member_id">
<a href="show_profile.php?member_id={$member_id}">Display Member id</a>
</div>
<script>
$("#show_profile_box").hide(100);
$("#display_member_id").click(function () {
$("#show_profile_box").show(500);
});
</script>
END_OF_HTML;
另请注意,变量不必用 {}
括起来,但这仍然是一个很好的做法。
这将创建一个类似“show_profile.php?member_id=3
”的链接,如果您单击该链接,将使用 $_GET['member_id'] 调用脚本= 3
。您甚至可以通过 click
事件中的 XHR 调用获取页面内容:
$.get($(this).attr('href'), function(data) { /* process data here */ });
关于php - 通过 Javascript 传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6940551/