Multiple solutions for cross-domain reasons in web development

Multiple solutions for cross-domain reasons in web development

Cross-domain reasons

This is due to the browser's same-origin policy restrictions;

Cross-domain means: when a request URL If any one of the protocol, domain name, and port number is different from the current page URL, it is cross-domain.

JSONP

This method is not suitable for development and can be said to be completely eliminated, but due to the complexity of implementation, the interviewer is very interested in this solution.

Core idea: The web page requests JSON data from the server by adding a src attribute of a <script> tag. After receiving the request, the server puts the data in the parameter position of a callback function with a specified name and passes it back.

Disadvantages: Requires backend cooperation to complete, can only send get requests

Implementation: Note that the backend returns a method call and actual parameters.

insert image description here

Nginx solution

insert image description here

Backend solution

Add annotations at the Controller layer:

@CrossOrigin(origins = "*", allowedHeaders = "*")

origins : List of allowed origin domains

allowedHeaders : The field types in the request headers allowed in cross-origin requests

The above is the detailed content of various solutions to the cross-domain reasons of web development. For more information about cross-domain solutions for web development, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • A brief discussion on the implementation principle of Webpack4 plugins
  • Web development js string concatenation placeholder and conlose object API detailed explanation
  • Web project development JS function anti-shake and throttling sample code
  • js to realize web message board function
  • JavaScript article will show you how to play with web forms
  • JavaScript web page entry-level development detailed explanation

<<:  How to use indexes to optimize MySQL ORDER BY statements

>>:  Detailed tutorial on building a local idea activation server

Recommend

Teach you how to build Tencent Cloud Server (graphic tutorial)

This article was originally written by blogger We...

5 super useful open source Docker tools highly recommended

Introduction The Docker community has created man...

Realizing tree-shaped secondary tables based on angular

First look at the effect: Code: 1.html <div cl...

Mysql inner join on usage examples (must read)

Grammatical rules SELECT column_name(s) FROM tabl...

Pure CSS to modify the browser scrollbar style example

Use CSS to modify the browser scroll bar style ::...

MySQL green decompression version installation and configuration steps

Steps: 1. Install MySQL database 1. Download the ...

Use nexus as a private library to proxy docker to upload and download images

1. Nexus configuration 1. Create a docker proxy U...

How to view the creation time of files in Linux

1. Introduction Whether the creation time of a fi...

How to configure MySQL master-slave synchronization in Ubuntu 16.04

Preparation 1. The master and slave database vers...

Using CSS3 to achieve progress bar effect and dynamically add percentage

During the project, I started using the js reques...

Detailed explanation of JS array methods

Table of contents 1. The original array will be m...

Docker deployment of Kafka and Spring Kafka implementation

This article mainly introduces the deployment of ...

How to copy MySQL table

Table of contents 1.mysqldump Execution process: ...