Document directory
- XMLHttpRequest has some common attributes:
- Common functions of XMLHttpRequest:
- Knowledge review:
I. Ajax Introduction
The full name of AJAX is Asynchronous JavaScript and XML. It is mainly used to update the whole page;
The purpose of AJAX is that if a webpage is slightly modified, the code of the entire page will be regenerated, which consumes a lot. While AJAX can only update partial pages;
Ajax is written in JavaScript code;
Ii. XMLHttpRequest
XMLHttpRequest is the core of Ajax. We send and accept data through XMLHttpRequest;
To obtain this object, we need to use the following code:
<script language="Javascript">var xmlHttp;function create(){if(window.XMLHttpRequest){xmlHttp = new XMLHttpRequest();}else{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}}</script>
The browser has two types of kernels: the IE kernel and the Firefox kernel. Therefore, you need to judge based on the current user's browser;
XMLHttpRequest has some common attributes:
(1) readystate: The Request status. (4 indicates that the response has been completed)
(2) onreadystatechange: called when readystate is changed, which is usually used for the return value of the callback function;
(3) responsetext: returns a plain text object;
(4) responsexml: the object that returns XML data;
(5) Status: return the current HTTP status (200 is normal)
Common functions of XMLHttpRequest:
(1) Open ("Get/Post", "url");: Create a request, specify post or get, and specify the destination URL to be sent;
(2) Send (PARAM);: send a request, usually Param = NULL;
Knowledge review:
In Javascript
(1) document. getelementbyid ("name"). innerhtml can be used to set the value of this control;
(2) The onblur event is called when the focus is lost;
Asynchronous login verification code:
Here Dao is used to connect to the database, so this code is ignored;
<HTML>
Note:
(1)No parentheses are required to call the callback function.
(2) spelling of readystate;
Checkservlet. Java
package org.servlet;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import org.dao.factory.*;public class CheckServlet extends HttpServlet{public void doGet(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException{String id = req.getParameter("id");PrintWriter out = resp.getWriter();boolean flag=false;try{flag = DAOFactory.getInstance().findById(id);}catch(Exception e){}if(flag){out.print("true");}else{out.print("false");}} }
Advantages of Asynchronous Authentication registration:
(1) You can know whether the user name is valid before submission. Many of them are used now.