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

Solve the problem of no my.cnf file in /etc when installing mysql on Linux

Today I wanted to change the mysql port, but I fo...

MySQL uses custom sequences to implement row_number functions (detailed steps)

After reading some articles, I finally figured ou...

Linux server quick uninstall and install node environment (easy to get started)

1. Uninstall npm first sudo npm uninstall npm -g ...

Implementation of waterfall layout + dynamic rendering

Table of contents Typical waterfall website Water...

Vue conditional rendering v-if and v-show

Table of contents 1. v-if 2. Use v-if on <temp...

Method example of safely getting deep objects of Object in Js

Table of contents Preface text parameter example ...

MySQL PXC builds a new node with only IST transmission (recommended)

Demand scenario: The existing PXC environment has...

How to move a red rectangle with the mouse in Linux character terminal

Everything is a file! UNIX has already said it. E...

Vue image cropping component example code

Example: tip: This component is based on vue-crop...

Implementation of element input box automatically getting focus

When making a form in a recent project, I need to...

How to increase HTML page loading speed

(1) Reduce HTTP requests. (Merge resource files a...

How to use HTML+CSS to create TG-vision homepage

This time we use HTML+CSS layout to make a prelim...

How to build a deep learning environment running Python in Docker container

Check virtualization in Task Manager, if it is en...

CSS to achieve text on the background image

Effect: <div class="imgs"> <!-...