当前位置:网站首页>Jsonp processing non homologous
Jsonp processing non homologous
2022-06-25 19:42:00 【Xibing_ G】
Ajax You can send... To the server without refreshing the page , because Homologous restriction , You cannot send requests that are not from the same source
What is non homologous :
Different agreements 、 Different domain names 、 Different ports , Any difference is non homologous
have access to jsonp To solve the problem of non homologous request sending
principle :
Write the non homologous request address in script Labeled src Properties of the , and src It is not restricted by homology Of
As src Properties of , Although it is a string type , But because it was written in script in , It will be executed as a script
Then, non homologous request access is realized
give an example 1:( stay 3000 Write... In the static file under the port script To visit 3001 Port of /test route )
Test let 3001 Port of test Routing returns 3000 Functions in the client fn() As a response
script Will execute in script mode , So it will be executed 3001 Response result of , It will also execute the client's fn function
So it's important to note that : In this test , Client's fn The function with the same name needs to be defined in script Before calling it
Server port 3000 Under the html File code :
<body>
<script>
function fn() {
console.log('3000 Port client fn Function called ');
}
</script>
<script src="http://localhost:3001/test"></script>
</body>3001 Server-side code :
const express = require('express');
const jsonp = express();
jsonp.get('/test', (req, res) => {
const result = 'fn()';
res.send(result);
})
jsonp.listen(3001);
console.log('3001 Monitored ');Server side Be careful matter : There will be fn Pass on to send Respond to the client in , And is In string format , If you will fn() To pass (const result=fn();), This means that it will be done directly on the server side fn Function call .

so :3000 Files under port pass script attribute src The method of introducing request address realizes non - homologous request access
边栏推荐
- SEO outsourcing reliable company, enterprise SEO outsourcing company which reliable?
- User management and permissions
- LeetCode-78-子集
- Kotlin Compose 终结toDo项目 点击可以编辑修改todo
- Error record: preg_ match(): Compilation failed: range out of order in character class at offset 13
- ECS 7-day practical training camp (Advanced route) -- day01 -- setting up FTP service based on ECS
- How to quickly close port 8080
- 3、 Hikaricp source code analysis of connection acquisition process III
- Network security detection and prevention test questions (V)
- 一、HikariCP获取连接流程源码分析一
猜你喜欢

Bloom filter

Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)

PostgreSQL user role permissions

削足适履 - 谈谈赛道上的坡道改造

LeetCode-101-对称二叉树

Automatic fitting when the applet reaches the top

Sorting out the latest data mining competition scheme!

Determine whether it is a web page opened on wechat

Print 1 cute every 100 milliseconds ~ with a running lantern effect

Vulnhub range - correlation:2
随机推荐
三、HikariCP获取连接流程源码分析三
二、HikariCP獲取連接流程源碼分析二
On Oracle full stack virtual machine -- graalvm
Ali visual AI training camp -day03- construction of electronic photo album (face and expression recognition)
QQ机器人:群成员自我禁言管理【最新beta2版本】
Dependency injection in PHP reflection implementation framework
Automatic fitting when the applet reaches the top
Applet password input box
Tcp/ip test questions (4)
Vulnhub range the planes: mercury
PHP synchronizes website content to hundreds of websites to improve SEO ranking
The native JS mobile phone sends SMS cases. After clicking the button, the mobile phone number verification code is sent. The button needs to be disabled and re enabled after 60 seconds
DARKHOLE 2
Lilda Bluetooth air conditioning receiver helps create a more comfortable road life
Install spoole
Network security detection and prevention test questions (4)
Convert word to PDF through libreoffice
QQ机器人疫情查询/疫情关注等【最新beta2版本】
QQ robot flash forwarding / recall message forwarding [latest beta2 version]
Network security detection and prevention exercises (III)