Ajax| form Submission
Yesterday in Csdn stroll, saw a netizen needs to solve some questions about the Ajax form submission, now put an example posted out, hope to the general enthusiasts help.
default.asp
Ajax-Sample1
//Please make sure the encoding of this page is set to UTF-8, otherwise there will be garbled
ajax Application Example: Registration module
ID:
Password:
when registering a user with an ID of Tony, the background verifies that the ID already exists and returns a message
To highlight no refresh effect, the server-side program will automatically perform the million addition operation
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 '
}
}
reg.asp
<%@ language= "VBSCRIPT" codepage= "65001"%>//codepage must be 650001, otherwise garbled, if there is HTML text, it must be set to UTF-8 code, otherwise will appear 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
%>
If you have any other questions, please follow the thread ~
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!