


The previous article introduced to you "How to use PHP to implement the user avatar upload function? (Detailed introduction)", this article continues to introduce to you what is Ajax? working principle? How to use Ajax to complete a GET request (with code) has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
What is Ajax?
The slang Ajax is used to describe a set of technologies that enable browsers to provide users with a more natural browsing experience. Before Ajax, Web sites forced users into a submit/wait/redisplay paradigm, where the user's actions were always synchronized with the server's "think time." Ajax provides the ability to communicate asynchronously with the server, freeing users from the request/response cycle. With Ajax, you can use JavaScript and DHTML to instantly update the UI when the user clicks a button and make an asynchronous request to the server to perform the update or query the database. When the request comes back, you can use JavaScript and CSS to update the UI accordingly instead of refreshing the entire page. Best of all, the user doesn't even know that the browser is communicating with the server: the website appears to be instantly responsive.
Ajax includes:
* Representation based on XHTML and CSS standards;
* Use Document Object Model for dynamic display and interaction;
* Use XMLHttpRequest Communicates asynchronously with the server;
* Bind everything using JavaScript.
How Ajax works:
The core of Ajax is the JavaScript object XmlHttpRequest. This object was first introduced in Internet Explorer 5 and is a technology that supports asynchronous requests. In short, XmlHttpRequest allows you to use JavaScript to make requests to the server and handle the responses without blocking the user.
How do we use Ajax to complete the GET request:
First, we need to create the Ajax object, and then, we need to create a callback for the request event. This part mainly completes two The first part is to obtain the response data from the server. The second part is to perform DOM operations on the current page, and these DOM operations are nothing more than some addition, deletion, modification and query operations in HTML. The third part is to call Ajax. The open method creates a URL request, and finally the user's URL request is sent to the client. The URL address that completes the get request has two formats: first: the current requested script has no parameters, for example, cheat.php, so This script does not require query parameters; the second one requires parameters. Just insert a question mark in the current script and enter the string; in fact, in actual development, we use JSON format data, but we obtain the data In essence, it is still a string, to be precise, it is a string in JSON format.
We first create an HTML file. Let's take a user's login form as an example: name it login, and we submit it using the get method. , we create two fields in the form, one is: account number; the second is: password, and then we add a submit button,
<!DOCTYPE html> <htmL> <head> <meta charset="UTF-8"> <title>用户登录</title> </head> <body> <div align=" cent'> <h3 id="用户登录">用户登录</h3> <form action="check.php" method="get"> <p>帐号: <input type="text" name="name" id="name"></p> <p>密码: <input type=" password" name=" password" id=" password"></p> <p><input type=" submit" id=" submit" value=" 提交"></p> </form> </div> </body> </html>
The code result is as follows;
Let’s write a script next. First, we get the submit button, and then we add a submit event. The code is as follows:
<script> Var submit = document . getElementByIdC' submit'); //获取提交按钮 submit. onclick = function { } </script>
Then, we create a PHP file (check.php) In this file we accept the data transmitted from the form, and we submit it in get mode. The submitted target script is (check.php)
The code is as follows:
<?php echo '<pre class="brush:php;toolbar:false">'; print_r($_GET);
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is Ajax? working principle? How to complete GET request with Ajax. For more information, please follow other related articles on the PHP Chinese website!

The article compares ACID and BASE database models, detailing their characteristics and appropriate use cases. ACID prioritizes data integrity and consistency, suitable for financial and e-commerce applications, while BASE focuses on availability and

The article discusses securing PHP file uploads to prevent vulnerabilities like code injection. It focuses on file type validation, secure storage, and error handling to enhance application security.

Article discusses best practices for PHP input validation to enhance security, focusing on techniques like using built-in functions, whitelist approach, and server-side validation.

The article discusses strategies for implementing API rate limiting in PHP, including algorithms like Token Bucket and Leaky Bucket, and using libraries like symfony/rate-limiter. It also covers monitoring, dynamically adjusting rate limits, and hand

The article discusses the benefits of using password_hash and password_verify in PHP for securing passwords. The main argument is that these functions enhance password protection through automatic salt generation, strong hashing algorithms, and secur

The article discusses OWASP Top 10 vulnerabilities in PHP and mitigation strategies. Key issues include injection, broken authentication, and XSS, with recommended tools for monitoring and securing PHP applications.

The article discusses strategies to prevent XSS attacks in PHP, focusing on input sanitization, output encoding, and using security-enhancing libraries and frameworks.

The article discusses the use of interfaces and abstract classes in PHP, focusing on when to use each. Interfaces define a contract without implementation, suitable for unrelated classes and multiple inheritance. Abstract classes provide common funct


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor