当前位置:网站首页>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
边栏推荐
- Uncover ges super large scale graph computing engine hyg: Graph Segmentation
- Vulnhub range - correlation:2
- Idea common plug-ins
- Verification code native JS canvas
- 2、 Hikaricp source code analysis of connection acquisition process II
- QQ robot epidemic situation query / epidemic situation concern [latest beta2 version]
- PHP database connection version1.1
- The meanings of /32, /48, /64 in IPv6 addresses
- Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)
- Solidity get quarterly time
猜你喜欢
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2

Gbpnzd firm offer for 14 months, simulation for 19 months, test stable

广州华锐互动VR全景为各行各业带来发展

LeetCode-101-对称二叉树

Sorting out the latest data mining competition scheme!

最新數據挖掘賽事方案梳理!

Google cloud SSH enable root password login

Ali visual AI training camp -day03- construction of electronic photo album (face and expression recognition)
![QQ robot: self forbidden words management of group members [latest beta2 version]](/img/1b/7dcc8ed344c9f62870d76f16b99f1d.png)
QQ robot: self forbidden words management of group members [latest beta2 version]

什么是算子?
随机推荐
Guangzhou Sinovel interactive creates VR Exhibition Hall panoramic online virtual exhibition hall
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
Network security detection and prevention test questions (II)
Determine whether it is a web page opened on wechat
QQ robot official plug-in loading configuration method [beta2 version]
Web components - Basics
[today in history] June 25: the father of notebook was born; Windows 98 release; First commercial use of generic product code
Read multiple associations from a field using delimiters in laravel
Electronic basic project construction & communication between main thread and rendering thread
Automatic fitting when the applet reaches the top
什么是算子?
Miner's Diary: why should I go mining on April 5, 2021
On location and scale in CNN
One night I worked as an XPath Terminator: XPath Helper Plus
ECS 7-day practical training camp (Advanced route) -- day04 -- build a portal using ECs and polardb
Is it safe to open an account with flush?
Huawei released two promotion plans to promote AI talent development and scientific research innovation
Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)
Tcp/ip test questions (I)
6、 Configuration resolution of hikariconfig