通过Ajax进行服务器端验证

通过Ajax进行服务器端验证

问题描述:

你好,
plz帮助使用ajax

Hello,
plz help for server side validation with ajax

服务器端验证Google是您的朋友:很好,经常拜访他.与在这里发布问题相比,他可以更快地回答问题.

一个简单的Google 使用您的标题作为搜索词 给出了 ^ ]其中最上面的一个是: ^ ]

尝试学会至少尝试做自己的基础研究.它可以节省您的时间,节省我们的时间,并且通常对每个人都更好...
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A simple google using your title as the search term gave over 2,000,000 hits[^] the top one of which was this: A Basic Approach to Server-side Data Validation with AJAX [^]

Try to learn to at least try to do your own basic research. It saves you time, saves us time, and generally is better for everybody...


Ajax代码

函数CheckUserName(){
var str = document.getElementById(<%= TextBox2.ClientID%>").value;
var xmlhttp;
如果(str =="){
document.getElementById("message1").innerHTML =";
返回;
}
if(window.XMLHttpRequest){//IE7 +,Firefox,Chrome,Opera,Safari的代码
xmlhttp = new XMLHttpRequest();
}
其他{//IE6,IE5的代码
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function(){
如果(xmlhttp.readyState == 4 && xmlhttp.status == 200){
message1.innerHTML = xmlhttp.responseText;

}
}
xmlhttp.open("GET","Demo.aspx?q =" + str,true);
xmlhttp.send();
}




然后在Demo.aspx中验证用户名并在页面上显示消息.
Ajax Code

function CheckUserName() {
var str = document.getElementById("<%=TextBox2.ClientID %>").value;
var xmlhttp;
if (str == "") {
document.getElementById("message1").innerHTML = "";
return;
}
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
message1.innerHTML = xmlhttp.responseText;

}
}
xmlhttp.open("GET", "Demo.aspx?q=" + str, true);
xmlhttp.send();
}




Then validate username in Demo.aspx & show message on page.