How does ajax work (with diagram)
This article mainly tells you about the working principle of ajax. It has certain reference value. Interested friends can learn about it. I hope it will be helpful to you.
Ajax refers to Asynchronous JavaScript and XML (asynchronous JavaScript and XML). The biggest advantage is that it can exchange data with the server and update part of the web page content without reloading the entire page. The basic principle of implementation is: the web page DOM object can accurately operate part of the content in the web page. XML, as a pure data storage carrier, allows the client and the server to exchange only the data of the web page content without additional information such as web page styles. , XMLHttpRequest is a request object that interacts with the server independently from the built-in request of the browser itself.
The abstract process of web application Ajax interacting with the server is as follows:
Detailed process explanation:
1: To use Ajax technology, the basics The basis is to create an XMLHttpRequest object, without which there is no possibility of asynchronous transmission:
1 2 3 4 5 6 7 8 |
|
2: Bind asynchronous operations in response to certain events in the web page: transmit through the xmlhttp object created above Request and carry data. Before making a request, you must first define the method of the request object, which file to submit to the server for request processing, what data to carry, and whether it is asynchronous.
Among them, like ordinary request submission data, there are two methods here: GET/POST
1 2 |
|
1 2 |
|
3: After the server receives the request, it passes the attached data as input for processing The requested file, for example here: pass fname=Henry&lname=Ford as input to the file /try/ajax/demo_get2.php. Then the file is processed according to the incoming data, and the result is finally returned and sent back through the response object. The client obtains the response content based on the xmlhttp object, and then calls the DOM object to partially modify the web page content based on the response content.
1 2 3 4 5 6 |
|
Among them, there are two types of response: string type and XML text. The difference between the two responses is extracted as follows:
responseText attribute returns the response in the form of a string:
1 |
|
If the response from the server is XML, needs to be parsed as an XML object, use responseXML :
1 2 3 4 5 6 7 |
|
Related tutorials:ajax video tutorial
The above is the detailed content of How does ajax work (with diagram). For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

Solana Blockchain and SOL Token Solana is a blockchain platform focused on providing high performance, security and scalability for decentralized applications (dApps). As the native asset of the Solana blockchain, SOL tokens are mainly used to pay transaction fees, pledge and participate in governance decisions. Solana’s unique features are its fast transaction confirmation times and high throughput, making it a favored choice among developers and users. Through SOL tokens, users can participate in various activities of the Solana ecosystem and jointly promote the development and progress of the platform. How Solana works Solana uses an innovative consensus mechanism called Proof of History (PoH) that is capable of efficiently processing thousands of transactions.

SpringDataJPA is based on the JPA architecture and interacts with the database through mapping, ORM and transaction management. Its repository provides CRUD operations, and derived queries simplify database access. Additionally, it uses lazy loading to only retrieve data when necessary, thus improving performance.

Build an autocomplete suggestion engine using PHP and Ajax: Server-side script: handles Ajax requests and returns suggestions (autocomplete.php). Client script: Send Ajax request and display suggestions (autocomplete.js). Practical case: Include script in HTML page and specify search-input element identifier.

VET Coin: Blockchain-based IoT ecosystem VeChainThor (VET) is a platform based on blockchain technology that aims to enhance the Internet of Things (IoT) field by ensuring the credibility of data and enabling safe transfer of value. supply chain management and business processes. VET coin is the native token of the VeChainThor blockchain and has the following functions: Pay transaction fees: VET coins are used to pay transaction fees on the VeChainThor network, including data storage, smart contract execution and identity verification. Governance: VET token holders can participate in the governance of VeChainThor, including voting on platform upgrades and proposals. Incentives: VET coins are used to incentivize validators in the network to ensure the

ShibaInu Coin: Dog-Inspired Cryptocurrency ShibaInu Coin (SHIB) is a decentralized cryptocurrency inspired by the iconic Shiba Inu emoji. The cryptocurrency was launched in August 2020 and aims to be an alternative to Dogecoin on the Ethereum network. Working Principle SHIB coin is a digital currency built on the Ethereum blockchain and complies with the ERC-20 token standard. It utilizes a decentralized consensus mechanism, Proof of Stake (PoS), which allows holders to stake their SHIB tokens to verify transactions and earn rewards for doing so. Key Features Huge supply: The initial supply of SHIB coins is 1,000 trillion coins, making it one of the largest cryptocurrencies in circulation. Low price: S

Polygon: A multifunctional blockchain that builds the Ethereum ecosystem Polygon is a multifunctional blockchain platform built on Ethereum, formerly known as MaticNetwork. Its goal is to solve the scalability, high fees, and complexity issues in the Ethereum network. Polygon provides developers and users with a faster, cheaper, and simpler blockchain experience by providing scalability solutions. Here’s how Polygon works: Sidechain Network: Polygon creates a network of multiple sidechains. These sidechains run in parallel with the main Ethereum chain and can handle large volumes of transactions, thereby increasing overall network throughput. Plasma framework: Polygon utilizes the Plasma framework, which

Beam Coin: Privacy-Focused Cryptocurrency Beam Coin is a privacy-focused cryptocurrency designed to provide secure and anonymous transactions. It uses the MimbleWimble protocol, a blockchain technology that enhances user privacy by merging transactions and hiding the addresses of senders and receivers. The design concept of Beam Coin is to provide users with a digital currency option that ensures the confidentiality of transaction information. By adopting this protocol, users can conduct transactions with greater confidence without worrying about their personal privacy information being leaked. This privacy-preserving feature makes Beam Coin work. MimbleWimble protocol enhances privacy by: Transaction merging: It combines multiple transactions into

AR Coin: Digital currency based on augmented reality technology AR Coin is a digital currency that uses augmented reality technology to provide users with the experience of interacting with digital content, allowing them to create immersive experiences in the real world. How it works AR Coin works based on the following key concepts: Augmented Reality (AR): AR technology overlays digital information on the real world, allowing users to interact with virtual objects. Blockchain: Blockchain is a distributed ledger technology used to record and verify transactions. It provides security and transparency to AR coins. Smart Contracts: Smart contracts are codes stored on the blockchain that are used to automate specific operations. They play a vital role in the creation and management of AR coins. The workflow of AR coins is as follows: Create AR body
