Ajax
Yesterday saw a netizen needs to solve some questions about the Ajax form submission, now put an example posted out, hope for the vast number of enthusiasts to help.
<!--registration Module-->default.asp
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>Ajax-Sample1</title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>//Please make sure the encoding of this page is set to UTF-8, otherwise there will be garbled
<meta name= "Author" content= "tonyhl[at]126.com"/>
<meta http-equiv= "Pragma" content= "No-cache"/>
<script language= "javascript" type= "Text/javascript" src= "Reg.js" ></script>
<link rel= "stylesheet" href= "Css.css" type= "Text/css" media= "All"/>
<style type= "Text/css" >
<!--
#Layer1 {
Position:absolute;
width:200px;
height:115px;
Z-index:1;
left:409px;
top:88px;
}
-->
</style>
<body>
<div id= "Layer1" >
<div id= "MSG" ></div>
</div>
ID: <input type= "text" id= "Regid"/>
Password: <input type= "Password" id= "Regpassword"/>
<input name= "F" type= "file"/>
<input type= "Submit" id= "Regsubmit" value= "register"/>
To highlight no refresh effect, the server-side program will automatically perform the million addition operation
</body>
<!----form data submission Script--->reg. Js
function GE (a) {return document.getElementById (a);}
function Check () {
if (GE (' Regid '). value== ') {ge (' msg '). innerhtml= ' id cannot be empty '; return false}
if (GE (' Regpassword '). value== ') {ge (' msg '). innerhtml= ' password cannot be empty '; return false}
var x=new activexobject ("msxml2.xmlhttp");
if (X) {
GE (' Regsubmit '). Disabled=true;
X.onreadystatechange=function () {
if (x.readystate==4) {
if (x.status==200) {
Eval (x.responsetext)
}
Else{ge (' msg '). Innerhtml=x.statustext}
}
Else{ge (' msg '). innerhtml= "Submitting data ..."}
};
X.open (' POST ', ' reg.asp ', true);
X.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');
var senddata = ' regid= ' +ge (' regid ') value+ ' ®password= ' +ge (' Regpassword '). value+ ' &file= ' +GE (' f '). Value
X.send (SendData)
}
else{
GE (' msg '). innerhtml= ' Your browser does not support XMLHttpRequest '
}
}
<!---process--->reg.asp
<%@ language= "VBSCRIPT" codepage= "65001"%>//codepage must be 650001, otherwise garbled, if there is HTML text, must be set to UTF-8 encoding , otherwise there will be garbled.
<%
Dim regid, regpassword, str
Regid=request.form ("Regid")
regpassword= Request.Form ("Regpassword")
F=request.form ("file")
Dim i, ii
ii = 0
For i = 0 to 1000000
ii = ii + i
Next
if regid= "" Or regpassword= "" then
str = "id and password must be filled in"
Else
if regid <> "Tony" then
str = "registered successfully, id" & regid & " , password is" & regpassword&f
else
str = "Registration failed, ID already exists"
end if
end if
response.write "GE (' msg '). Innerhtml= ' & str & "'; GE (' Regsubmit '). Disabled=false "
Response.End
%>
This example I think more comprehensive, I use AJAX form to submit a beginner example, quite enough! If there is a mistake, please correct me!