ajax| Refresh | Without refreshing the advantages of Ajax technology where is it, do not understand. To see the simplest example, assume that when the user registers, to determine whether the user entered the name has been occupied, assuming that the input number 1: "OK" (indicating that the correct, you can use); Enter additional characters: "Error" (indicating errors, already occupied).
Using AJAX technology to achieve
Code: t.htm
<script>
function f(){
var req =new ActiveXObject("Microsoft.XMLHTTP");
req.open("GET","t.asp?t1="+t1.value, true);
req.onreadystatechange = function(){
if (req.readyState == 4) {
if (req.status == 200) {
msg.innerText = req.responseXML.documentElement.tagName;
}
}
}
req.send(null);
}
</script>
<div>1:显示"OK"; 其他字符:显示"Error"</div>
<input id=t1 value=1>
<input type=button value="检测" >
<div id=msg></div>
Code:
t.asp
<%
Response.ContentType="text/xml"
if request.querystring("t1")="1" then
response.write("<OK/>")
else
response.write("<ERROR/>")
end if
%>
Traditional brushless new technology of ASP
Code t.htm
<script>
function f(){
document.getElementById("o").src="t.asp?t1="+t1.value
}
</script>
<div>1:显示"OK"; 其他字符:显示"Error"</div>
<input id=t1 name=1 value=1>
<input type=button value="检测" >
<div id=msg></div>
<iframe src="t.asp" style="display:none" id=o></iframe>
Code t.asp
<%
if request.querystring="" then response.end
ss="ERROR"
if request.querystring("t1")="1" then ss="OK"
%>
<script>parent.msg.innerText="<%=ss%>"</script>
Both are no Refresh Extraction server (database) data and real-time display in the customer segment, then why do you now have to use Ajax, but also to consider the Chinese coding problems. Ajax in the end where the good, please tell me in detail, I was a little, but did not understand the beauty of Ajax.
Here, we only discuss the Ajax invoke the same domain under the ASP file (that is, write their own ASP program), the Thief program, steal news, weather forecasts and other applications are not discussed at the moment
, the example is very simple, no error handling, and so on, only for discussion.