如何在PHP中使用点击元素的内部HTML,如下所述?如何将数据从JavaScript传输到PHP?
$(function() {
$(".topic-list-items").click(function() {
// document.getElementById("content-of-the-topic").innerHTML= $(this).context.innerHTML;
<?php
$dbhost = '127.0.0.1';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$conn) {
die('Could not connect: '.mysql_error());
}
// here I want to table name dynamically, that is, "SELECT id FROM table". $variable
$sql = "SELECT id FROM ";
//$ variable is the clicked element's innerHTML
mysql_select_db('entries_database');
$retval = mysql_query($sql, $conn);
if (!$retval) {
die('Could not get data: '.mysql_error());
}
?>
});
});
你应该使用AJAX,如果你想从JS通过一些值到PHP – Darvex
我建议ü使用jQuery的AJAX功能得到从PHP file.That的响应得到了内部HTML中的jQuery函数并将其发送到php文件。然后运行正常的php查询并将查询结果作为json响应发送到jquery函数。 –