【www.gdgbn.com--php应用】
ajx.php教程
$link=mysql_connect("localhost","root","root");
-
mysql_select_db("abd",$link);
$gb2312string=iconv( "utf-8", "gb2312//ignore" , $requestajaxstring); //ajax中先用encodeuricomponent对要提交的中文进行编码
mysql_query("set names gb2312");
$name=$_get[name];
if($name){
$sql=mysql_query("select * from stu where name="".$name.""");
$info=mysql_fetch_array($sql);
header("content-type: text/html;charset=gb2312"); //指定发送数据的编码格式为gb2312
if (!$info){
echo "无记录!";
}else{ echo $info[sheng]; }
}
?>
复制代码
test.php
-
<script language="javascript">
var http_request = false;
function createrequest(url) {
//初始化对象并发出xmlhttprequest请求
http_request = false;
if (window.xmlhttprequest) { //mozilla等其他浏览器
http_request = new xmlhttprequest();
if (http_request.overridemimetype) {
http_request.overridemimetype("text/xml");
}
} else if (window.activexobject) { //ie浏览器
try {
http_request = new activexobject("msxml2.xmlhttp");
} catch (e) {
try {
http_request = new activexobject("microsoft.xmlhttp");
} catch (e) {}
}
}
if (!http_request) {
//alert("不能创建xmlhttp实例!");
return false;
}
http_request.onreadystatechange = alertcontents; //指定响应方法
http_request.open("get", url, true); //发出http请求
http_request.send(null);
}
function alertcontents() { //处理服务器返回的信息
if (http_request.readystate == 4) {
var objhelpid = document.getelementbyid("usernamehelp");
var objhelp1id = document.getelementbyid("usernamehelp1");
if (http_request.responsetext != ""){objhelp1id.innerhtml = http_request.responsetext;objhelpid.innerhtml = "";}
else{objhelpid.innerhtml = http_request.responsetext;objhelp1id.innerhtml = "";}
}
}
</script>
<script language="javascript">
function checkname() {
var name = form1.name.value;
if(name=="") {
window.alert("请填写用户名!");
form1.name.focus();
return false;
}
else {
createrequest("ajx.php?name="+name+"&nocache="+new date().gettime());
}
}
</script>