我有这个 ajax 函数:
function getpage(page,div){
var url = page+"&sid="+Math.random();
var xhr;
try { xhr = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e)
{
try { xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e2)
{
try { xhr = new XMLHttpRequest();
}
catch (e3) {
xhr = false;
}
}
}
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4){
if(xhr.status == 200)
document.getElementById(div).style.display= "block";
document.getElementById(div).innerHTML = xhr.responseText;
}else{
document.getElementById(div).innerHTML = '<img src="./pic/load.gif" />';
}
};
xhr.open( "GET", url, true);
xhr.send(null);
}
我有 singup 表格(使用 smarty 模板设计):
<div><input style="width:300px" class="inp" type="text" onkeyup="getpage('./ajax.php?action=regnewuser&usern={$uname}','register')" name="User_name" placeholder="username" required /></div><div class="hr" id="register"></div>
我有这个 ajax.php 代码:
if($act == 'regnewuser'){
$usern = protect($_GET['usern']);
$sql = $db->query("SELECT USER_NAME FROM ".$pre."USERS");
while($row = $db->record()){
$dbuname = strtolower($row['USER_NAME']);
$uname2 = strtolower($usern);
}
if(empty($usern)){
echo '<div class="rd">please fill the box !!</div>';
}elseif(strlen($usern) < 4){
echo '<div class="rd">too short !!</div>';
}elseif(strlen($usern) > 50){
echo '<div class="rd">too tall !!</div>';
}elseif($dbuname == $uname2){
echo '<div class="rd">not available !!</div>';
}
}
但结果总是“请填写”;
我认为模板形式的问题!
我应该做什么但进入模板以获得正确的结果?