Front-end and back-end interaction model & http protocol & Ajax introduction

0. Foreword: This article is only a summary of the theory, functions, and methods in the "front-end and back-end interaction model & http protocol & Ajax introduction", which is used to review knowledge and make a summary, without specific implementation code.


1. Front-end and back-end interaction models:

  • The front end sends requests, and the back end responds to requests.
  • In addition to the http protocol, there are some other protocols, such as the TCP protocol, which is used in games, and the UDP protocol.
    insert image description here

2. Features of http protocol:

  • 1. For front-end and back-end interaction, most of them use http protocol.
  • 2. Request first, then respond, and there are many types of transmitted data.
  • 3. It will be disconnected immediately after one request, saving server resources.
  • 4. Contains request header and request body
  • 5. Introduction to http status code: 200 is normal, 400 is abnormal, 500 is server error

3. Introduction to Ajax:

  • It is a web development technology that can create interactive web development, which allows partial interaction between web pages and server data.
  • The characteristic is that it can be realized through asynchronous requests.
  • Process: Make network asynchronous or synchronous requests through Ajax—analyze the obtained data (usually in json format)—embed the parsed data into webpage tags through js operations.
  • Note: In the process of interacting between the front-end and the back-end server through Ajax, you may encounter cross-domain problems. For cross-domain problems, you must first understand the same-origin policy (the same-origin policy is a browser security policy that requires a domain name (ip), protocol (http), port must be consistent), for cross-domain problems, the solution is as follows:
    • 1. The front-end and back-end codes are placed on the same server
    • 2. The back-end settings allow cross-domain
    • 3. Bypass the same-origin policy, use Jsonp instead of Ajax
  • Two types of requests commonly used in front-end and back-end interactions: get and post
    • 1. Get is used for interaction with a small amount of data (2k), and is fast. It is often used to obtain data, and can also submit data. Its parameters can be directly passed to the backend through the url.
    • 2. Post is used for interaction with a large amount of data (within 4G), and the speed is slow. It is often used to submit data or obtain data. Its parameters are placed in the http request body through the send function to simulate a form and passed to the backend.

4. Jsonp technology:

  • Role: Solve cross-domain problems, bypass Ajax for front-end and back-end interactions.
  • Implementation method: the front-end directly calls the back-end url, and the back-end returns an html parameter passing function string. After the string is returned to the front-end, it will be automatically recognized as a function execution, but make sure that the function exists in the front-end.

Guess you like

Origin blog.csdn.net/sz1125218970/article/details/130994950