Ajax form Submission Instance

Source: Internet
Author: User
Tags empty end return
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+ ' &regpassword= ' +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!




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.