tpl文件:
<form action="index.php" method="post">
<center><table>
<tr><th>显示详细信息</th></tr>
<{foreach from=$list item="value"}>
<tr>
<td id="name_<{$value.id}>" bgcolor="00FF00"><{$value.id}></td>
<td bgcolor="FF00FF" onmouseover="showDetail(<{$value.id}>)" onmouseout="hideDetail(<{$value.id}>)"><{$value.username}></td>
</tr>
<{/foreach}>
</table></center>
</form>
<script>
function showDetail(id){
var xhr;
if(window.ActiveXObject){
xhr=new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}
xhr.open("POST","index.php?c=user&time="+new Date().getTime()+"&a=process",true);
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.onreadystatechange=callback;
xhr.send("id="+id);
function callback(){
if(xhr.readyState==4){
if(xhr.status==200)
{
//alert(xhr.responseText);
var json = eval('('+xhr.responseText+')');
//alert(json.id);
var new_div = document.createElement('div');
new_div.style.backgroundColor = "#ccc";
new_div.style.position = "absolute";
new_div.id = "new_div"+id;
new_div.style.marginLeft = '170px';
new_div.innerHTML = "id:"+json.id+"<br/>username:"+json.username+"<br/>content:"+json.content;
document.getElementById('name_'+id).appendChild(new_div);
}
}
}
}
function hideDetail(id){
var new_div = document.getElementById("new_div"+id);
document.getElementById("name_"+id).removeChild(new_div);
}
</script>
userController.class.php文件:
public function showDetaiAction(){
$userModel=new userModel('localhost','root','','baidu');
$rows=$userModel->searchAll();
//file_put_contents("d://test.txt",$rows,FILE_APPEND);
$this->smarty->assign('list',$rows);
$this->smarty->display('showDetail.tpl');
}
public function processAction(){
$id=$_REQUEST['id'];
$userModel=new userModel('localhost','root','','baidu');
$rows=$userModel->getOne($id);
echo json_encode($rows);
}
userModel.class.php文件:
public function getOne($id){
$sql="select * from c where id='".$id."'";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
//var_dump($rows);
return $row;
}