当前位置:网站首页>1-21 jsonp interface
1-21 jsonp interface
2022-06-30 21:29:00 【Endless pie】
review JSONP The concept and characteristics of
Concept : Browser pass
characteristic :
- JSONP It doesn't belong to the real Ajax request , Because it's not used XMLHttpRequest This object .
- JSONP Support only GET request , I won't support it POST、PUT、DELETE Equal request .
establish JSONP Interface precautions
If... Has been configured in the project CORS Cross-domain resource sharing , In order to prevent conflict , Must be configured CORS The middleware previously declared JSONP The interface of . otherwise JSONP The interface will be processed as open CORS The interface of .
Realization JSONP Interface steps
- Get the name of the callback function sent by the client
- Get through JSONP Data sent to the client as
- According to the data from the first two parts , Splice a string of function calls .
- Concatenate the string obtained in the previous step , Response to
// Must be configured cors Previous configuration JSONP
app.get('/api/jsonp',(req,res)=>{
// Get the name of the function
const funcname = req.query.callback
const data = {
name:'zs',
age:22
}
const scriptStr = `${funcname}(${JSON.stringify(data)})`
res.send(scriptStr)
})
边栏推荐
- ClickHouse distributed表引擎
- MySQL batch update
- 1-13 express监听GET和POST请求&处理请求
- asp.net core JWT传递
- 1-20 预检请求
- ca i啊几次哦啊句iu家哦11111
- How to run jenkins build, in multiple servers with ssh-key
- Is it safe to open an account for stock trading on mobile phones?
- Coefficient of variation method matlab code [easy to understand]
- 科研中遇到迷茫困惑如何向前一步?如何在科研中发挥女性优势?
猜你喜欢

Icml2022 | utility theory of sequential decision making

Introduction of 3D Max fine model obj model into ArcGIS pro (II) key points supplement

USBCAN分析仪的配套CAN和CANFD综合测试软件LKMaster软件解决工程师CAN总线测试难题

《ClickHouse原理解析与应用实践》读书笔记(2)
Understand what MySQL index push down (ICP) is in one article

ICML2022 | 序列决策的效用理论

asp. Net core JWT delivery

Oracle 数据库表结构 Excel 导出

It is urgent for enterprises to protect API security

AKK菌——下一代有益菌
随机推荐
Sqlserver string type converted to decimal or integer type
Introduction of 3D Max fine model obj model into ArcGIS pro (II) key points supplement
Upgrade Kube with unknown flag: --network plugin
Is it safe to open an account for stock trading on mobile phones?
Clickhouse Native Monitoring item, System table Description
NCAT detailed introduction (Reprint)
Understand what MySQL index push down (ICP) is in one article
1-20 预检请求
USBCAN分析仪的配套CAN和CANFD综合测试软件LKMaster软件解决工程师CAN总线测试难题
1-17 express中间件
对多态的理解
Text recognition svtr paper interpretation
Flutter 嵌套地狱?不存在的,ConstraintLayout 来解救!
How to move forward when facing confusion in scientific research? How to give full play to women's advantages in scientific research?
sdfsdf
Learning summary
Double solid histogram / double y-axis
科研中遇到迷茫困惑如何向前一步?如何在科研中发挥女性优势?
Sqlserver gets the data of numbers, Chinese and characters in the string
A small step in code change and a big leap in thinking