当前位置:网站首页>Jsonp non homologous interaction (click trigger)
Jsonp non homologous interaction (click trigger)
2022-06-25 19:42:00 【Xibing_ G】
When the button is clicked btn1 when , Dynamically create script label , Then assign the request address to src attribute , Add to the page to execute
script There is onload event , When src After the address request script is executed, it will trigger ,so Sure “ burn the bridge after crossing it ”
Continue to test the request access of different ports
3000 The client file code under port :( Be careful : This time fn2 Parameters can be reserved data Of , Reserved for server delivery )
<body>
<button id="btn1"> Click me to send a request 1</button>
<script>
function fn2(data) {
alert('fn2 Called ');
console.log(data);
}
</script>
<script>
var btn1 = document.getElementById('btn1');
btn1.addEventListener('click', function() {
// establish script label
var script = document.createElement('script');
// Set up src attribute , take script Append to page
script.src = "http://localhost:3001/better?callback=fn2";
document.body.appendChild(script);
// for fear of script Label via btn Infinite clicks trigger and infinite generation , When it is loaded, it is meaningless
script.addEventListener('load', function() {
// burn the bridge after crossing it
document.body.removeChild(script);
})
})
</script>
</body>
3001 Port server code :
const express = require('express');
const jsonp = express();
jsonp.get('/better', (req, res) => {
// Receive... In the request address callback Value , That is, to receive the function name passed by the client
const fnName = req.query.callback;
const result = fnName + '({name:"xx"})';
res.send(result);
})
jsonp.listen(3001);
console.log('3001 Monitored ');
On the server side : Received the request parameters first callback( At this time, the function name in the request content received by the server is fn2)
Then put this function name and () as well as Parameters Splicing
Last pass send Respond to clients
The server-side response data can also be obtained
边栏推荐
- 什么是算子?
- Tcp/ip test questions (V)
- Google SEO external chain releases 50+ website platform sharing (e6zzseo)
- 揭秘GES超大规模图计算引擎HyG:图切分
- SQL is used for field data types in various databases
- Tcp/ip test questions (III)
- 1、 Hikaricp source code analysis of connection acquisition process I
- Record Baidu search optimization thinking analysis
- Gbpnzd firm offer for 14 months, simulation for 19 months, test stable
- Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)
猜你喜欢
Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology
Applet wx Request encapsulation
Process of vacuum and vacuum full
Vulnhub range the planes: mercury
ECS 7-day practical training camp (Advanced route) -- day03 -- ecs+slb load balancing practice
QQ robot: self forbidden words management of group members [latest beta2 version]
Guangzhou Sinovel interactive creates VR Exhibition Hall panoramic online virtual exhibition hall
DARKHOLE 2
Record Baidu search optimization thinking analysis
[C language practice - print the upper triangle and its deformation (with blank version)]
随机推荐
What is an operator?
最新数据挖掘赛事方案梳理!
Web components - Basics
Tcp/ip test questions (III)
Go language installation and uninstallation
QQ robot flash forwarding / recall message forwarding [latest beta2 version]
JQ implements tab switching
二、HikariCP獲取連接流程源碼分析二
Error record: preg_ match(): Compilation failed: range out of order in character class at offset 13
PostgreSQL division considerations
Convert word to PDF through libreoffice
Yum command
谈谈CNN中的位置和尺度问题
Vulnhub range - the planes:venus
Elastic high-performance computing on the cloud supports the rapid development of the life science industry, reducing costs and increasing efficiency
wooyun-2014-065513
广州华锐互动打造VR展厅全景在线虚拟展厅
JS some small problems about adding and accessing values to arrays
Bloom filter
QQ robot epidemic situation query / epidemic situation concern [latest beta2 version]