


Do you know the basic development of Ajax? Detailed explanation of the basic development steps of ajax (with examples)
This article mainly talks about the basic development steps of ajax. If you want to have a deeper understanding of ajax development, you must know the development steps. Although it is the most basic, it can also let people know how to use it. ajax development. Start reading this article now
What is ajax? What is the use?
The full name of Ajax is "Asynchrous Javascript And XML", which refers to a web development technology for creating interactive web applications. It is a technology for quickly creating dynamic web pages to improve the efficiency of interaction between browsers and servers. It can replace the traditional web interaction mode.-
How to understand this synchronization and asynchronousness?
What is the traditional synchronous interaction model?
In the traditional model, the synchronous interaction mode is used. The client browser makes a request to the server, and then waits until the server responds to the request, and cannot perform other operations.
What is the asynchronous interaction model of mainstream technology?
In the Ajax asynchronous interaction mode, there is an additional transfer object Ajax engine between the client browser and the server. When the client browser submits a request to the Ajax engine, the Ajax engine is responsible for transferring the request information to the server. , so that after the client browser sends the request, it can continue the operation instead of being in a waiting state. After the server processes the Ajax engine request, it passes the response to the Ajax engine, and the Ajax engine updates the client browser page. Ajax development steps
Step one: Get the XMLHttpRequest object.
You can find sample code in the xml document of w3school.
var xmlhttp = null;if(window.XMLHttpRequest){ //这个是针对浏览器IE7及其7以上的版。 xmlhttp = new XMLHttpRequest(); }else if(window.ActiveXObject){ //这个是针对浏览器5到7的版本。 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
Step 2: Register the callback function.
xmlhttp.onreadystatechange = function(){ };
onreadystatechange is an event handler for events triggered by each state change.
The third step: open("method","URL",async,"uname","pswd")
is only used to set the request method, URL path, and whether to synchronize. No request is sent.
Parameters | Function |
---|---|
method | Send request method, the optional parameters are: GET, POST and PUT. |
URL | The URL path to be sent, you can use absolute paths and relative paths. |
async | Whether the request should be processed asynchronously. You can also leave it blank. The default value is true. |
true, script processing will continue after send() is sent, that is, asynchronous processing. | |
false, the script will wait for a response before continuing script processing, that is, synchronous processing. | |
uname | It has not been used yet, and the documentation does not explain it. Just don’t write it. |
pswd | It has not been used yet, and the documentation does not explain it. Just don’t write it. |
What if the URL requires parameters?
If it is a get request, concatenate the parameters directly after the url.
For example: xmlhttp.open("get","http://www.baidu.com?name=xiaosan");
If it is a post request, multiple setting operations must be performed:
For example: xmlhttp.open("post","http://www.baidu.com");
xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded" );
xmlhttp.send("name=xiaosan");
The function of setRequestHeader("label","value") is to add the label/value pair to the http header that you want to be sent.
Step 4: send(content)
Send the request. If there are no parameters, it is written as send(null).
Step 5: Perform specific data operations in the callback function.
Before this, you need to understand some properties of XMLHttpRequest.
Properties | Description |
---|---|
State occurs When it changes, something can be triggered. | |
See the table below for details | |
Number return status, such as "OK" is 200, "Not Found" is 404, etc. | |
String return status, such as "OK", "Not Found", etc. | |
Return the response as a string. | |
Returns the response in XML. What is returned is an XML object that can be parsed using DOM |
represents the status interpretation | |
---|---|
Uninitialized state, represents the loading state before the XMLHttpRequest object is created | |
, open operation. | |
Loaded status, send operation. | |
In interactive status, response data has been received, but only the response header and the body have not been received. | |
Complete status, all http response reception is completed. |
Parameters | Function |
---|---|
method | Send request method, the optional parameters are: GET, POST and PUT. |
URL | The URL path to be sent, you can use absolute paths and relative paths. |
async | Whether the request should be processed asynchronously. You can also leave it blank. The default value is true. |
true, script processing will continue after send() is sent, that is, asynchronous processing. | |
false, the script will wait for a response before continuing script processing, that is, synchronous processing. | |
uname | It has not been used yet, and the documentation does not explain it. Just don’t write it. |
pswd | It has not been used yet, and the documentation does not explain it. Just don’t write it. |
What if the URL requires parameters?
If it is a get request, concatenate the parameters directly after the url.
For example: xmlhttp.open("get","http://www.baidu.com?name=xiaosan");
If it is a post request, multiple settings must be performed:
For example: xmlhttp.open("post","http://www.baidu.com");
xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded" );
xmlhttp.send("name=xiaosan");
The function of setRequestHeader("label","value") is to add the label/value pair to the http header that you want to be sent.
Step 4: send(content)
Send the request. If there are no parameters, it is written as send(null).
Step 5: Perform specific data operations in the callback function.
Before this, you need to understand some properties of XMLHttpRequest.
Properties | Description |
---|---|
State occurs When it changes, something can be triggered. | |
See the table below for details | |
Number return status, such as "OK" is 200, "Not Found" is 404, etc. | |
String return status, such as "OK", "Not Found", etc. | |
Return the response as a string. | |
Returns the response in XML. What is returned is an XML object, which can be parsed using DOM |
represents the status interpretation | |
---|---|
Uninitialized state, represents the loading state before the XMLHttpRequest object is created | |
, open operation. | |
Loaded status, send operation. | |
In interactive status, response data has been received, but only the response header and the body have not been received. | |
Complete status, all http response reception is completed. |
AJAX User Manual column to learn). If you have any questions You can leave a message below to ask questions.
The above is the detailed content of Do you know the basic development of Ajax? Detailed explanation of the basic development steps of ajax (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.

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.

How to use Ajax functions to achieve asynchronous data interaction With the development of the Internet and Web technology, data interaction between the front end and the back end has become very important. Traditional data interaction methods, such as page refresh and form submission, can no longer meet user needs. Ajax (Asynchronous JavaScript and XML) has become an important tool for asynchronous data interaction. Ajax enables the web to use JavaScript and the XMLHttpRequest object
