


What are the workflows of AJAX? Introduction to ajax workflow (with examples)
This article mainly talks about the workflow of ajax, as well as the principle of ajax and the introduction of some commonly used attributes. Now let us read this article together
AJAX stands for "Asynchronous JavaScript and XML".
is a web development technology for creating interactive web applications. It:
Uses XHTML CSS to represent information;
Uses JavaScript to operate DOM (Document Object Model) for dynamic display and interaction;
Uses XML and XSLT for data exchange and related operations;
Uses the XMLHttpRequest object Asynchronous data exchange with the web server;
Use JavaScript to bind everything together.
AJAX principle:
AJAX does not refer to a single technology, but organically utilizes a series of related technologies. Its core is the JavaScript object XmlHttpRequest, which allows us to use JavaScript to make requests to the server and process responses without blocking the user. AJAX uses an asynchronous interaction process, which introduces an intermediary between the user and the server, thereby eliminating the processing-waiting-processing-waiting shortcomings in the network interaction process. The user's browser loads the AJAX engine when performing tasks. The AJAX engine is written in JavaScript and is usually hidden in a hidden frame. It is responsible for compiling the user interface and interacting with the server. The AJAX engine allows the interaction process between the user and the application software to proceed asynchronously, independent of the communication between the user and the network server. Now, you can use Javascript to call the AJAX engine instead of generating an HTTP user action. In-memory data editing, page navigation, and data verification, which do not require reloading the entire page, can be executed by AJAX. Using AJAX, you can Bringing visible convenience to JSP, developers, and end users.
Since the core of Ajax is the XmlHttpRequest object, it must be introduced:
Commonly used attributes:
Onreadystatechange specifies the event processing function when the readyState attribute changes. Just write
readyState to indicate the current status of the Ajax request. Read only Its value is represented by a number.
0 means not initialized. The open method has not been called yet
1 means loading. The open method has been called, but the send method has not been called yet
2 means that it has been loaded. send has been called. The request has started
3 means the interaction is in progress. The server is sending a response
4 means complete. The response is sent
Every time the readyState value changes, the readystatechange event will be triggered.
responseText Returns the response information as a string. Read-only. It's either HTML, XML or plain text, depending on what the server is sending. The responseText property is only available when the readyState property value becomes 4, indicating that the Ajax request has ended.
responseXML Format the response information into an Xml Document object and return it, read-only. The responseXML attribute is available only when the server sends data with correct header information. MIME type must be text/xml
status Returns the http status code of the current request. Read-only
Common status codes and their meanings:
404 Page not found (not found)
. The file has not been Modification)
In the XMLHttpRequest object, the status codes sent by the server are stored in the status attribute. By comparing this value with 200 or 304, you can ensure whether the server has sent a successful response
(If you want to know more, go to the PHP Chinese website
AJAX Development Manual
column to learn)
Common methods:
Open creates a new http request and specifies the request method, URL and verification information
Send Sends the request to the http server and receives the response. If the request is get, it will not be sent. Any data
setRequestHeader individually specifies a certain http header of the request
AJAX workflow:
1 Object initialization
function createXmlHttpRequest(){ var xmlHttp; try{ //Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e){ try{ //Internet Explorer xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){} } } return xmlHttp; }
2 Send request
Call The open and send methods of the XMLHttpRequest object are, in order, called after the open call is completed.
xmlHttp.open("get","../servlet/RegisterServlet?timeStamp="+new Date().getTime(),true) xmlHttp.send(null);
If the parameter of send is sent in Post mode, it can be any content that you want to pass to the server, but you must first call the setRequestHeader method and modify the MIME category:
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
3 The server receives and processes the data and returns it, and specifies the event handler to process the return information
Each time the readyState attribute Changes will trigger the readystatechange event. Just assign the corresponding handler function name to the onreadystatechange attribute of the XMLHttpRequest object.
xmlHttp.onreadystatechange = function(){ if (xmlHttp.readystate == 4) { if (xmlHttp.status == 200 || xmlHttp.status == 304) {//XMLHttpRequest对成功返回的信息有两种处理方式://responseText: 将传回的信息当字符串使用;//responseXML:将传回的信息当XML文档使用,可以用DOM处理。 } } };
4 Client reception
5 Modify the client page Content
This article ends here (if you want to see more, go to the PHP Chinese websiteAJAX User Manual column to learn), there are questions You can leave a message below to ask questions.
The above is the detailed content of What are the workflows of AJAX? Introduction to ajax workflow (with examples). For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools