Ajax entry-level learning Summary

Source: Internet
Author: User
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.

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.