html:
<script type="text/javascript" src="/oa/js/ajex.js"></script>
<input type="text" name="name" id="name" onblur="doAjax( 'get_student_name.php?username='+this.value )" />php:<?php
include ("../../inc/mysqlconn.php");//$sql = "select * from noa_students where name like '%". $_GET['username']. "%' ";
$sql="select * from noa_students where name like '%" .$_GET['username']. "%' ";
$result = mysql_query ( $sql );
while ( $rows = mysql_fetch_array ( $result ) )
{
echo $rows ["name"];
}
?>jx:
var xmlhttp;
function createXHR()
{
try
{
xmlhttp=new ActiveXObject("Msxm12.XMLHTTP"); //支持不同浏览器版本,下同
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType("text/xml");
}
}
catch(e){}
}
}
if(!xmlhttp)
{
return false;
}
}function doAjax( url )
{
createXHR();
xmlhttp.onreadystatechange=requestAjax;
xmlhttp.open( "GET", url, true );
xmlhttp.send( null );
}function requestAjax()
{
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
document.getElementById('chk').innerHTML = xmlhttp.responseText;
}
}
}
// JavaScript Documentphp访问是有结果的,不知道哪里错了?
<script type="text/javascript" src="/oa/js/ajex.js"></script>
<input type="text" name="name" id="name" onblur="doAjax( 'get_student_name.php?username='+this.value )" />php:<?php
include ("../../inc/mysqlconn.php");//$sql = "select * from noa_students where name like '%". $_GET['username']. "%' ";
$sql="select * from noa_students where name like '%" .$_GET['username']. "%' ";
$result = mysql_query ( $sql );
while ( $rows = mysql_fetch_array ( $result ) )
{
echo $rows ["name"];
}
?>jx:
var xmlhttp;
function createXHR()
{
try
{
xmlhttp=new ActiveXObject("Msxm12.XMLHTTP"); //支持不同浏览器版本,下同
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType("text/xml");
}
}
catch(e){}
}
}
if(!xmlhttp)
{
return false;
}
}function doAjax( url )
{
createXHR();
xmlhttp.onreadystatechange=requestAjax;
xmlhttp.open( "GET", url, true );
xmlhttp.send( null );
}function requestAjax()
{
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
document.getElementById('chk').innerHTML = xmlhttp.responseText;
}
}
}
// JavaScript Documentphp访问是有结果的,不知道哪里错了?
你应该是说,输入用户名后, <div id="chk"> </div>里面显示可用的用户名(或邮箱名),然后点击,文本框自动赋值?是,我该怎么做呢?
<script type="text/javascript" src="/oa/js/ajex.js"> </script>
<input type="text" name="name" id="name" onblur="doAjax( 'get_student_name.php?username='+this.value )" />
<div id="chk"> </div> //加个这个东西就OK了
function requestAjax()
{
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
//获取返回的结果
var text = xmlhttp.responseText;
//对结果进行分析,比如说将不同的结果以数组形式输出,每条结果以<P></P>进行换行。
然后再给<P onclick='setText();'>加个onclick事件,点击以后,在setText函数里对input进行赋值
}
}
}
是,我该怎么做呢?
[/Quote] document.getElementById('chk').innerHTML = xmlhttp.responseText;
你这里得到的responseText属性不该只是// [email protected]这样的链接,应该写成HTML标记。譬如下面这个返回的值
<html>
<head>
<script language="javascript">
function changeEmail(value)
{
document.getElementById('email').value = value;
}
</script>
</head><body>
<input name="email" type="text" />
<div id="chk">
<input type="radio" name="radio" id="radio" onClick="changeEmail('XXX_users_123');" />1<br />
<input type="radio" name="radio" id="radio" onClick="changeEmail('XXX_users_456');" />2<br />
<input type="radio" name="radio" id="radio" onClick="changeEmail('XXX_users_789');" />3<br /></div>
</body>
</html>
你可以看看网易免费邮箱注册时的提示
http://uinfo.mail.163.com/mailregAll/reg0.jsp
126的就可以更换
http://reg.126.com/regmail126/userRegist.do?action=start&from=
http://www.rsywx.net/xajax/demos/index.php
你的input文本框id是name,那么返回值,即xmlhttp.responseText值,应该诸如:<script language="javascript">
function changeEmail(value)
{
document.getElementById('name').value = value;
}
</script>
<input type="radio" name="radio" id="radio" onClick="changeEmail('XXX_users_123');" />[email protected]<br />
<input type="radio" name="radio" id="radio" onClick="changeEmail('XXX_users_456');" />[email protected]<br />
<input type="radio" name="radio" id="radio" onClick="changeEmail('XXX_users_789');" />[email protected]<br />
OK?