public function baiduAction(){
$this->smarty->display('baidu.tpl');
}
<head>
<script>
function init(){
document.getElementById('dv').style.display='none';
}
function textAjax(con){
var xhr;
if(window.ActiveXObject){
xhr=new ActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}
var url='index.php?c=user&a=baiduAll';
xhr.open('POST',url,true);
xhr.Xonreadystatechange= callback;
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send('con='+con);
function callback(){
if(xhr.readyState==4){
if(xhr.status==200){
var con=eval('('+xhr.responseText+')');
document.getElementById('dv').style.display='block';
var str='';
for(var i=0;i<con.length;i++){
str+="<span>"+con[i].name+"</span><br>";
document.getElementById('dv').innerHTML=str;
}
}
}
}
}
</script>
</head>
<body Xοnlοad="init()">
<center>
<h3>百度一次,你就知道</h3>
<table>
<tr>
<td>
<form action="#" method="post">
<input type="text" size="30" id="search" Xοnkeyup="textAjax(this.value)" />
<div id="dv" align="left" style=" position:relative; background-color:#CCC; border:dashed #999"></div>
</td><td>
<input type="submit" value="搜索" size="10" />
</td>
</form>
</tr>
</table>
</center>
</body>
public function baiduAllAction(){
$con=$_REQUEST['con'];
$userModel=new userModel("localhost","news","root","123");
$row=$userModel->getbd($con);
$rows=json_encode($row);
echo $rows;
}
public function getbd($con){
$sql="select * from new where name like '$con%'";
$res=mysql_query($sql);
while($row=mysql_fetch_assoc($res)){
$rows[]=$row;
}
return $rows;
}