Simple Ajax instance

Source: Internet
Author: User

Index. jsp

<% @ Page contenttype = "text/html; charset = GBK" %> <br/> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en"> <br/> <HTML> <br/> <pead> <br/> <title> check.html </title> </P> <p> <meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3 "> <br/> <meta http-equiv =" Description "content =" this is my page "> </P> <p> <! -- <LINK rel = "stylesheet" type = "text/CSS" href = ". /styles.css "mce_href =" styles.css "> --> </P> <p> </pead> <br/> <MCE: Script Type =" text/JavaScript "> <! -- <Br/> var http_request = false; <br/> function send_request (URL) {// initialization, specify the processing function, and send the request function <br/> http_request = false; <br/> // start to initialize the XMLHTTPRequest object <br/> If (window. XMLHttpRequest) {// Mozilla Browser <br/> http_request = new XMLHttpRequest (); <br/> If (http_request.overridemimetype) {// set the mime Category <br/> http_request.overridemimetype ('text/xml'); <br/>}< br/> else if (window. activexobject) {// IE Browser <br/> try {<br/> http_request = new activexobject ("msxml2.xmlhttp"); <br/>} catch (E) {<br/> try {<br/> http_request = new activexobject ("Microsoft. XMLHTTP "); <br/>}catch (e) {}< br/>}< br/> If (! Http_request) {// exception. An error occurred while creating the object instance. <br/> window. alert ("the XMLHTTPRequest object instance cannot be created. "); <br/> return false; <br/>}< br/> http_request.onreadystatechange = processrequest; <br/> // determine the request sending method and URL, and whether to execute the following code synchronously <br/> http_request.open ("get", URL, true ); <br/> http_request.send (null); <br/>}< br/> // function for processing returned information <br/> function processrequest () {<br/> If (http_request.readystate = 4) {// judge the object status <br/> If (http_re Quest. status = 200) {// information returned successfully. Start to process the information <br/> alert (http_request.responsetext ); <br/>} The else {// page is abnormal <br/> alert ("the page you requested has an exception. "); <Br/>}< br/> function usercheck () {<br/> var F = document. form1; <br/> var username = f. username. value; <br/> If (username = "") {<br/> window. alert ("the user name can not be null! "); <Br/> F. username. focus (); <br/> return false; <br/>}< br/> else {<br/> send_request ('check1. JSP? Username = '+ username); <br/>}</P> <p> // --> </MCE: SCRIPT> <br/> <body> <br/> <form name = "form1" Action = "" method = "Post"> <br/> User Name: <input type = "text" name = "username" value = ""> <br/> <input type = "button" name = "check" value = "check" onclick = "usercheck () "> <br/> <input type =" Submit "name =" Submit "value =" Submit "> <br/> </form> <br/> </body> <br/> </ptml> <br/> This article is from the csdn blog, reprinted please indicate the source: http://blog.csdn.net/sunrisefe/archive/2006/01/16/580474.aspx 

 

Check1.jsp

<% @ Page contenttype = "text/html; charset = gb2312 "Language =" Java "errorpage =" "%> <br/> <% <br/> string username = request. getparameter ("username"); <br/> If ("educhina ". equals (username) <br/>{< br/> out. print ("the user name has been registered. Please change to another user name. "); <Br/>}< br/> else <br/>{< br/> out. Print (" the user name has not been used. You can continue. "); <Br/>}< br/> %>

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.