52,797
社区成员
发帖
与我相关
我的任务
分享
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
var xmlHttp=false;
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e2)
{
xml=false;
}
}
if(!xmlHttp)
{
xml=new XMLHttpRequest();
}
function checkUser(userName)
{
var url="DisposeEvent.aspx?Name="+userName;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=backInfo;
xmlHttp.send(null);
}
function backInfo()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
alert("false");
if(xmlHttp.responseText=="true")
{
document.getElementById('message').innerHTML="对不起,此用户已存在!";
}
else
{
document.getElementById('message').innerHTML="恭喜您,此用户可注册!";
}
}
}
}
</script>
</head>
<table style="width: 500px; height: 164px">
<tr>
<td style="width: 80px">
用户名:</td>
<td style="width: 100px">
<input id="userName" type="text" onchange="checkUser(document.getElementById('userName').value)"/></td>
<td style="width: 100px">
<div id="message"></div>
</td>
</tr>
<tr>
<td style="width: 80px">
密码:</td>
<td style="width: 100px">
<input id="userPwd" type="text" /></td>
<td style="width: 100px">
</td>
</tr>
<tr>
<td colspan="3">
<input id="RegBtn" type="button" value="注册" /></td>
</tr>
</table>
public partial class DisposeEvent : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
User user = new User();
if (user.LoadUserData(Request.QueryString["Name"].ToString()))
{
Response.Write("true");
Response.End();
}
else
{
Response.Write("false");
Response.End();
}
}
}
public bool LoadUserData(string userName)
{
int Result = 0;
bool exist = false;
SqlConnection con = DB.createDB();
SqlParameter pUserName = new SqlParameter("@UserName", SqlDbType.VarChar, 100);
pUserName.Value = userName;
string SqlText = string.Format("select count(*) from Users where UserName={0}", pUserName);
SqlCommand sqlcmd = new SqlCommand(SqlText,con);
sqlcmd.Parameters.Add(pUserName);
try
{
con.Open();
Result = Convert.ToInt32(sqlcmd.ExecuteScalar());
if (Result > 0)
{
exist = true;
}
}
catch(SqlException ex)
{
throw new Exception(ex.Message,ex);
}
finally
{
con.Close();
}
return exist;
}
public class DB
{
public DB()
{
}
public static SqlConnection createDB()
{
string sqlcon = "server=(local);database=practice;uid=sa;pwd=;";
SqlConnection con = new SqlConnection(sqlcon);
return con;
}
}
var url="DisposeEvent.aspx?Name="+escape(userName); <!--encodeURI也可以--!>
if(Request.QueryString["Name"]!=null)
{}
user.LoadUserData(Request.QueryString["Name"].Trim().ToString())
function backInfo()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
alert(xmlHttp.responseText);//这里调试一下看看到底是什么
if(xmlHttp.responseText=="true")
{
document.getElementById('message').innerHTML="对不起,此用户已存在!";
}
else
{
document.getElementById('message').innerHTML="恭喜您,此用户可注册!";
}
}
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Javascript编写Ajax实例</title>
<script language="javascript">
var http_request = false;
function send_request(url) {
http_request = false;
if(window.XMLHttpRequest) {
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/html');
}
}
else if (window.ActiveXObject) {
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;
http_request.open("GET", url, false);
http_request.send(null);
}
function processRequest() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
document.getElementById("result").innerHTML = http_request.responseText;
}
else
{
alert("您所请求的页面有异常。");
}
}
}
document.getElementById("result").innerHTML="正在查询,请稍候";
send_request('http://localhost/ajax.aspx');
}
</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<input type="button" name="search" value="查询服务器时间" onClick="dosearch()"><br />
<span id="result"></span>
</form>
</body>
</html>
function checkUser(userName)
{
var url="DisposeEvent.aspx?Name="+encodeURI(userName)//编码;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=backInfo;
xmlHttp.send(null);
}
<%@ Page Language="C#" Debug="true"%>
<%@ Import NameSpace="System" %>
<%@ Import NameSpace="System.Web" %>
<%@ Import NameSpace="System.Collections" %>
<%@ Import NameSpace="Newtonsoft.Json" %>
<script language="C#" runat="server">
Shelly.Product insProduct = new Shelly.Product();
Shelly.Category insCategory = new Shelly.Category();
Shelly.Template insTemplate = new Shelly.Template();
public void Page_load(object sender, EventArgs e){
String outType = (Request.QueryString["o"]!=null)?Request.QueryString["o"].ToString().Trim():"jssz";
String mod = (Request.QueryString["mod"]!=null)?Request.QueryString["mod"].ToString().Trim():"";
....