ajax & network related

ajax

AJAX  Full name  Async JavaScript and XML(XML Is an extensible markup language)
AJAX It is a technology that can exchange data with the server and update some web pages without reloading the whole page

Four steps to create ajax

var xhr = new XMLHttpRequest()   // Create a core object XMLHttpRequest instance
xhr.open('GET','https://cnodejs.org/api/v1/topics') / / link with the server open (type of request, file location on the server, true (asynchronous) or false (synchronous))
xhr.send({page:1,tab:'ask',limit:10})  // Send (send the request to the server. It is a string, which is generally used for post)
xhr.onreadystatechange = function(){ // The onreadystatechange event is triggered whenever the readyState changes.
	console.log(xhr.readyState) // readyState contains the state of XMLHttpRequest. 0 request is uninitialized. 1 server establishes a link. 2 request acceptance. 3 request processing. 4 request is completed and the response is ready
	console.log(xhr.status)
	if(xhr.readyState == 4 && xhr.status == 200 ){
		console.log(xhr.responseText)  // responseText gets the response data in string form.
	} 		
}
// The abort() method can be used to cancel the asynchronous request, and an error will be reported before the send() method. You will get a null value before responseText.

Encapsulating Ajax

function ajax(options = {
        url:"https://cnodejs.org/api/v1/topics ", / / request address
        data:null, //Data to send
        method:"GET", //Request mode
        success:function (){}, //Callback after success
        fail:function() {}, //Callback after failure
        async: false, //Synchronous or asynchronous
        headers: { //Request header information
            token: "tokenString"
        }
    }){
        let xhr = new XMLHttpRequest();
        xhr.open(options.method,options.url,options.async);
        for(let headKey in options.headers){
            xhr.setRequestHeader(headKey,options.headers[headKey]);
        }
        xhr.onreadystatechange = function (){
            console.log(xhr.status);//http status code 100 200 300 400 500
            if(xhr.readyState === 4){//I've got the corresponding information from the server
                switch (xhr.status){
                    case 200:
                        options.success && options.success(JSON.parse(xhr.responseText))
                        break;
                    default:
                        options.fail && options.fail(xhr.responseText)
                }
            }
        };
        xhr.send(options.data)
    }

Network related

HTTP

  1. HTTP protocol (HyperText Transfer Protocol) is the most widely used network transmission protocol on the Internet. All WWW files must comply with this standard.
  2. HTTP is a communication protocol based on TCP/IP to transfer data (HTML files, picture files, query results, etc.).
  3. The default HTTP port number is 80, but you can also change it to 8080 or other ports.
  4. The HTTP protocol works on the client server architecture. As an HTTP client, the browser sends all requests to the HTTP server, that is, the WEB server, through the URL.
  5. HTTP request method
  6. HTTP status code

    Common are
    404 Not Found
    200 OK request succeeded

HTTPS

HTTPS (full name: Hyper Text Transfer Protocol over SecureSocket Layer) is an HTTP channel with security as the goal. On the basis of HTTP, the security of the transmission process is guaranteed through transmission encryption and identity authentication. (in other words, HTTP encryption)

Homology & cross domain

Homology protocol: / / Domain Name: the same port number means homology. If one is different, it means non homology (cross domain)

www

WWW is the abbreviation of World Wide Web, also known as web, 3W, etc. WWW is the integration of information discovery technology and Hypertext Technology Based on client / server mode.

WWW server organizes information into illustrated hypertext through hypertext markup language (HTML), which can be used to describe hypermedia. Multimedia such as text, graphics, video and audio are called hypermedia. Hypermedia is essentially the same as hypertext

domain name

Domain Name, also known as domain, is the name of a computer or computer group on the Internet, which is composed of a string of names separated by dots. It is used to locate and identify the computer during data transmission (sometimes it also refers to geographical location).

Different number of domain name segments (separated by dot ".")
First level domain name baidu.cn
Secondary domain name: video.baidu.cn
Level 3 domain name: webG.video.buidu.cn
The top-level domain name is the same as the first-level domain name, such as baidu.com
The top-level domain name does not contain other level domain names.

Common domain name suffix:. com international /. cn China /. gov government /. org official /. net system /. io blog /. vip

url analysis

http://www.baidu.cn:80/index.html?lx=teacher#video
Transport protocol: / / Domain Name: port number / path and name of the requested resource? Question mark parameter part

HTML

HTML refers to HyperText Markup Language
HTML is a language used to describe Web pages.
HTML documents contain HTML tags and text content
HTML documents are also called web pages
HTML is not a programming language, but a markup language

XHTML refers to Extensible HyperText Markup Language
XML refers to eXtensible Markup Language
XML is a markup language much like HTML.
XML is designed to transmit data, not display data.

Web browser

Web browsers (such as Google browser, Internet Explorer, Firefox, Safari) are used to read HTML files and display them as web pages.

W3C

W3C (English: World Wide Web Consortium), also known as W3C Council, is the main international standards organization of the world wide web.
W3C enables everyone to share resources on the Internet.

Tags: Javascript Ajax http

Posted on Sun, 03 Oct 2021 17:45:35 -0400 by zavin