2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
ajax Full name Asynchronous JavaScript and XML (asynchronous JavaScript and XML)。
AJAXIt is a web development technology for creating interactive web applications.The core dependency is the XMLHttpRequest object provided by the browser, which enables the browser to issue HTTP Request and receive HTTP Response. It enables interaction with the server without refreshing the page.
Native AJAX syntax format:
- let xhr = new XMLHttpRequest();
- xhr.open('get','js/index.json',true);
- xhr.send();
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4 && xhr.status == 200) {
- let text = xhr.responseText;
- console.log(text);
- let data = JSON.parse(text);
- console.log(data);
- }
- };
The packaged AJAX provided by jQuery is faster and suitable for use in development projects. Native AJAX is easier to understand and easy to understand.
jQuery syntax format:
- $.ajax({
- type: "GET",
- url: 'js/exercise.json',
- data: {},
- headers:'',
- datatype:'',
- async:'',
- success: function(result) {
- console.log(result);
- data = result;
- },
-
- Error: function(e) {
- console.log(e.status);
- console.log(e.responseText);
- },
-
- });