变量通过ajax传递,它是数据库名称。当链接被点击时,它应该从数据库中检索数据。链接和变量位于同一页面上。这里是链接的代码:通过ajax传递字符串变量
$x = strval($_GET['x']);
echo '<a href="#" onclick="showInformation('.$x.')">'.$seatid.'</a>';
$ x变量包含数据库的表名称。这里是AJAX代码:
function showInformation(str)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtInfo").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getinfo.php?x="+str,true);
xmlhttp.send();
}
这里是getinfo.php:
<?php
session_start();
$_SESSION['login']="1";
$x = strval($_GET['x']);
$con = mysql_connect('localhost','root','Newpass123#','seatmapping');
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db('seatmapping');
$sql="SELECT name, seatid FROM $x WHERE seatid = 1";
$result = mysql_query($sql) or die("Query Error " . mysql_error());
...
...
?>
我不能让它当我点击链接它不会显示从数据工作表。 请帮帮我。任何形式的帮助表示赞赏。在此先感谢..
公开表名并不是一个好的做法.. –
'//代码为IE6,IE5' ......我无言以对。 –
2014年不使用jQuery ajax ...我无言以对。 :) –