


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!

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

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



Title: Methods and code examples to resolve 403 errors in jQuery AJAX requests. The 403 error refers to a request that the server prohibits access to a resource. This error usually occurs because the request lacks permissions or is rejected by the server. When making jQueryAJAX requests, you sometimes encounter this situation. This article will introduce how to solve this problem and provide code examples. Solution: Check permissions: First ensure that the requested URL address is correct and verify that you have sufficient permissions to access the resource.

jQuery is a popular JavaScript library used to simplify client-side development. AJAX is a technology that sends asynchronous requests and interacts with the server without reloading the entire web page. However, when using jQuery to make AJAX requests, you sometimes encounter 403 errors. 403 errors are usually server-denied access errors, possibly due to security policy or permission issues. In this article, we will discuss how to resolve jQueryAJAX request encountering 403 error

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make

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.

Ajax (Asynchronous JavaScript and XML) allows adding dynamic content without reloading the page. Using PHP and Ajax, you can dynamically load a product list: HTML creates a page with a container element, and the Ajax request adds the data to that element after loading it. JavaScript uses Ajax to send a request to the server through XMLHttpRequest to obtain product data in JSON format from the server. PHP uses MySQL to query product data from the database and encode it into JSON format. JavaScript parses the JSON data and displays it in the page container. Clicking the button triggers an Ajax request to load the product list.

In order to improve Ajax security, there are several methods: CSRF protection: generate a token and send it to the client, add it to the server side in the request for verification. XSS protection: Use htmlspecialchars() to filter input to prevent malicious script injection. Content-Security-Policy header: Restrict the loading of malicious resources and specify the sources from which scripts and style sheets are allowed to be loaded. Validate server-side input: Validate input received from Ajax requests to prevent attackers from exploiting input vulnerabilities. Use secure Ajax libraries: Take advantage of automatic CSRF protection modules provided by libraries such as jQuery.

Ajax is not a specific version, but a technology that uses a collection of technologies to asynchronously load and update web page content. Ajax does not have a specific version number, but there are some variations or extensions of ajax: 1. jQuery AJAX; 2. Axios; 3. Fetch API; 4. JSONP; 5. XMLHttpRequest Level 2; 6. WebSockets; 7. Server-Sent Events; 8, GraphQL, etc.
