如何检验用户名的唯一性,求助! 可能楼上没有理解我的意思,我遇到的困难是如果直接提交给判断的php页面,返回表单页就要刷新了,原来的填写的内容就没有了我只想找个办法,判断好在表单页显示一下结果,就可以了!明白了么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 还有就是我的问题不在用php操作数据库上,而是在如何从表单页面上调用判断代码,又不会刷新表单页面。我是不是很罗嗦啊! 回复:看下ajax的相关知识goo了一下,看了,不错!但是有没有更纯净一点的办法呢? window.open("http://www.xxx.com/bbb.php?username='+document.all.form1.xxx.value");这个和asp,php有关系么 sample1_1.php<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>无标题文档</title><script language="javascript"> var http_request = false; function send_request(url) {//初始化、指定处理函数、发送请求的函数 http_request = false; //开始初始化XMLHttpRequest对象 if(window.XMLHttpRequest) { //Mozilla 浏览器 http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) {//设置MiME类别 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) { // 异常,创建对象实例失败 window.alert("不能创建XMLHttpRequest对象实例."); return false; } http_request.onreadystatechange = processRequest; // 确定发送请求的方式和URL以及是否同步执行下段代码 http_request.open("GET", url, true); http_request.send(null); } // 处理返回信息的函数 function processRequest() { if (http_request.readyState == 4) { // 判断对象状态 if (http_request.status == 200) { // 信息已经成功返回,开始处理信息 alert(http_request.responseText); } else { //页面不正常 alert("您所请求的页面有异常。"); } } } function userCheck() { var f = document.form1; var username = f.username.value; if(username=="") { window.alert("用户名不能为空。"); f.username.focus(); return false; } else { send_request('sample1_2.jsp?username='+username); } }</script><link href="css/style.css" rel="stylesheet" type="text/css"></head><body><form name="form1" action="" method="post">用户名:<input type="text" name="username" value=""> <input type="button" name="check" value="唯一性检查" onClick="userCheck()"><input type="submit" name="submit" value="提交"></form></html> sample2_2.php<?php//add code to query//then return resultecho "恭喜你,可以注册"?> smarty模板处理里面有不有类似split的函数 菜鸟 求解答 PHP 模糊查询 使用easyphp,为什么同样的代码在两台电脑上一台正常一台不行 谁给一段简单的无闪烁刷新页面的程序,最好用 xmlhttp的, ice_berg16(寻梦的稻草人)和52juanjuan(Fibona)两位请进---补分 请教Header的问题! 图片域能传递值吗? 新手请教session问题! 請教大家我要從 A 頁中轉到 B 頁中以下各處(1, 2, 3)我怎麼實現??? 网络编程 请教一个函数 提交内容会自动转义?
我是不是很罗嗦啊!
goo了一下,看了,不错!
但是有没有更纯净一点的办法呢?
这个和asp,php有关系么
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
var http_request = false;
function send_request(url) {//初始化、指定处理函数、发送请求的函数
http_request = false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) { //Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//设置MiME类别
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) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
http_request.onreadystatechange = processRequest;
// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("GET", url, true);
http_request.send(null);
}
// 处理返回信息的函数
function processRequest() {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
alert(http_request.responseText);
} else { //页面不正常
alert("您所请求的页面有异常。");
}
}
}
function userCheck() {
var f = document.form1;
var username = f.username.value;
if(username=="") {
window.alert("用户名不能为空。");
f.username.focus();
return false;
}
else {
send_request('sample1_2.jsp?username='+username);
}
}
</script>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head><body>
<form name="form1" action="" method="post">
用户名:<input type="text" name="username" value="">
<input type="button" name="check" value="唯一性检查" onClick="userCheck()">
<input type="submit" name="submit" value="提交">
</form></html>
<?php
//add code to query
//then return result
echo "恭喜你,可以注册"
?>