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

Summary of MySQL usage specifications

1. InnoDB storage engine must be used It has bett...

MySQL Community Server 5.7.19 Installation Guide (Detailed)

MySQL official website zip file download link htt...

What are the differences between sql and mysql

What is SQL? SQL is a language used to operate da...

Detailed explanation of MySQL 8.0.18 commands

Open the folder C:\web\mysql-8.0.11 that you just...

Vue uses custom instructions to add watermarks to the bottom of the page

Project Scenario Add a custom watermark to the en...

Encoding problems and solutions when mysql associates two tables

When Mysql associates two tables, an error messag...

Differences between MySQL CHAR and VARCHAR when storing and reading

Introduction Do you really know the difference be...

How to show or hide common icons on the desktop in Windows Server 2012

Windows Server 2012 and Windows Server 2008 diffe...

How many pixels should a web page be designed in?

Many web designers are confused about the width of...

Select web page drop-down list and div layer covering problem

Questions about select elements in HTML have been...

Detailed explanation of nginx-naxsi whitelist rules

Whitelist rule syntax: BasicRule wl:ID [negative]...

How to allow external network access to mysql and modify mysql account password

The root account of mysql, I usually use localhos...

HTML basic summary recommendation (text format)

HTML text formatting tags 標簽 描述 <b> 定義粗體文本 ...