Home Backend Development PHP Tutorial Detailed explanation of Ajax features and garbled code problems

Detailed explanation of Ajax features and garbled code problems

Dec 19, 2017 pm 01:33 PM
ajax Garbled characters question

The full name of ajax is asynchronous javascript and XML, which is asynchronous js and XML. It is a partial refresh, asynchronous operation. This article introduces to you the characteristics of ajax and the problem of garbled characters. Friends who are interested should take a look at it. I hope it can help you.

Before I explain, let me tell you about the linear data structure. We can think of a single linear data structure as a line segment. A line segment has a beginning and a tail. You all know that a single thread means that the head of a line segment has no front area. , there is no trailing area at the tail, and each element in the middle has two elements before and after it. When one element is missing, two elements will know and tell you at the same time. And it doesn’t even work without a single element.

The callback function passes function A as a parameter to function B, and function B executes function A. The most common uses of callback functions are the success() and error() functions we use when requesting data with ajax, as well as the first parameter in setInterval, which also uses callback functions. Callback function, callback function, the literal meaning of callback is to turn around and go back to walk that road again. So ajax turns around and walks again when the callback function success() or error is triggered, and then it is asynchronous. At the same time, ajax is asynchronous. Similar to it, there is es6's promise (asynchronous synchronous operation) .

The process of the browser is multi-process. As for why it is the same as why you call it XXX~

The second question is when the omnipotent front-end encounters ajax acquisition Everyone should be confused about why the background data is garbled.
-Maybe it’s a network speed problem, the network is too slow.

-Maybe the encoding format is not uniform, and your backend brothers have tricked you, hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha

#
//1.创建xmlhttpRequest对象
var xhr;
try{
   xhr = new XMLHttpRequest();
   console.log(5555)
}
catch(e){
//ie浏览器低版本兼容
   xhr = new ActiveXobject("Microsoft.XMLHTTP");
}
finally{
  console.log(1111)
}
// try{} catch{} finally{}在这里是处理异常的方法,用if{}else{}也ok 
//if(window.XMLHttpRequest){
 // xhr = new XMLHttpRequest();
//  }else{
  //ie浏览器低版本的兼容
 // xhr = new ActiveXobject("Microsoft.XMLHTTP")
//}
//2.建立异步连接
xhr.open("get","url/+string",true/false);//true是异步,false是同步
//xhr.open("post","url",true/false)
//3.发送异步请求
 xhr.send(null);//get
 xhr.send(string);//post
//4.获取返回数据
 xhr.onreadystatechange = function (){
  if((xhr.readystate)==4&&(xhr.status==200)){
   var data = xhr.responseText;
   var data = JSON.parse(data);
   show(data);
}
}
function show(data){
 document.getElementById("p1").innerHTML = data;
}
Copy after login

Related recommendations:


Examples to explain Ajax asynchronous request technology

Common use of AJAX What is the syntax

AJAX principle and CORS cross-domain method

The above is the detailed content of Detailed explanation of Ajax features and garbled code problems. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve Chinese garbled characters in Linux How to solve Chinese garbled characters in Linux Feb 21, 2024 am 10:48 AM

The Linux Chinese garbled problem is a common problem when using Chinese character sets and encodings. Garbled characters may be caused by incorrect file encoding settings, system locale not being installed or set, and terminal display configuration errors, etc. This article will introduce several common workarounds and provide specific code examples. 1. Check the file encoding setting. Use the file command to view the file encoding. Use the file command in the terminal to view the encoding of the file: file-ifilename. If there is "charset" in the output

How to solve the 403 error encountered by jQuery AJAX request How to solve the 403 error encountered by jQuery AJAX request Feb 20, 2024 am 10:07 AM

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.

Tips for dealing with garbled Chinese file names in PHP Tips for dealing with garbled Chinese file names in PHP Feb 27, 2024 pm 02:18 PM

Tips for dealing with garbled Chinese file names in PHP During the development process, we often encounter the problem of garbled Chinese file names, especially when processing files uploaded by users. In PHP, how to correctly handle garbled file names is a common and important problem. This article will introduce some techniques for dealing with garbled Chinese file names and provide specific code examples to help readers better deal with this challenge. Problem description: When users upload files, the Chinese file names sometimes appear to be garbled. This is because different operating systems and browsers

How to solve the problem of garbled characters when importing Chinese data into Oracle? How to solve the problem of garbled characters when importing Chinese data into Oracle? Mar 10, 2024 am 09:54 AM

Title: Methods and code examples to solve the problem of garbled characters when importing Chinese data into Oracle. When importing Chinese data into Oracle database, garbled characters often appear. This may be due to incorrect database character set settings or encoding conversion problems during the import process. . In order to solve this problem, we can take some methods to ensure that the imported Chinese data can be displayed correctly. The following are some solutions and specific code examples: 1. Check the database character set settings In the Oracle database, the character set settings are

How to solve jQuery AJAX request 403 error How to solve jQuery AJAX request 403 error Feb 19, 2024 pm 05:55 PM

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

How to deal with garbled characters in Linux terminal How to deal with garbled characters in Linux terminal Mar 20, 2024 pm 03:12 PM

How to deal with the problem of garbled characters in the Linux terminal. When using the Linux system, sometimes the text displayed in the terminal will be garbled. This brings inconvenience to us when using the terminal and needs to be dealt with in time. This article will introduce how to deal with some common Linux terminal garbled problems, and provide specific code examples. Problem 1: Garbled Chinese characters on the terminal. Garbled Chinese characters on the terminal are usually caused by incorrect character encoding settings on the terminal. We can solve this problem by modifying the terminal's character encoding settings. #View the current terminal

PHP and Ajax: Building an autocomplete suggestion engine PHP and Ajax: Building an autocomplete suggestion engine Jun 02, 2024 pm 08:39 PM

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.

How to solve the problem of garbled characters displayed on Win11 when booting? Two solutions to the garbled characters displayed on Win11 boot How to solve the problem of garbled characters displayed on Win11 when booting? Two solutions to the garbled characters displayed on Win11 boot Feb 29, 2024 pm 12:16 PM

Win11 is Microsoft's latest operating system, but some users may encounter the problem of displaying garbled characters when booting, which will affect the normal use of the system. This article will introduce some methods to solve this problem. Method 1: 1. Press the [Win+S] key combination, or click the [Search icon] next to the start icon on the taskbar. In the opened Windows search, enter [Control Panel] in the search box, and then click [Open]. The best matching control panel application out of the control panel window; 2. In the control panel window, switch to the [Category] view mode, and then click [Clock and Zone-Region]; 3. In the zone window, switch to the [Management] tab, and then click [Change] System Regional Settings]; 4. [Uncheck] Beta version: Use Unicode

See all articles