当前位置:网站首页>1-21 JSONP接口
1-21 JSONP接口
2022-06-30 21:27:00 【画不完的饼】
回顾JSONP的概念与特点
概念:浏览器通过
特点:
- JSONP不属于真正的Ajax请求,因为它没有使用XMLHttpRequest这个对象。
- JSONP仅支持GET请求,不支持POST、PUT、DELETE等请求。
创建JSONP接口的注意事项
如果项目中已经配置了CORS跨域资源共享,为了防止冲突,必须在配置CORS中间件之前声明JSONP的接口。否则JSONP接口会被处理成开启了CORS的接口。
实现JSONP接口的步骤
- 获取客户端发送过来的回调函数的名字
- 得到要通过JSONP形式发送给客户端的数据
- 根据前两部得到的数据,拼接出一个函数调用的字符串。
- 把上一步拼接得到的字符串,响应给客户端的
//必须在配置cors之前配置JSONP
app.get('/api/jsonp',(req,res)=>{
//得到函数的名称
const funcname = req.query.callback
const data = {
name:'zs',
age:22
}
const scriptStr = `${funcname}(${JSON.stringify(data)})`
res.send(scriptStr)
})
边栏推荐
- Reading notes of Clickhouse principle analysis and Application Practice (2)
- Understand what MySQL index push down (ICP) is in one article
- 攻防演练中的防泄露全家福
- Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?
- 多态在代码中的体现
- Text recognition svtr paper interpretation
- Understanding polymorphism
- 1-20 预检请求
- MySQL高级篇3
- Markdown notes concise tutorial
猜你喜欢

Oracle 数据库表结构 Excel 导出

个人开发的渗透测试工具Satania

Markdown notes concise tutorial

文本生成模型退化怎么办?SimCTG 告诉你答案

SQL server extracts pure numbers from strings

申请Vector 总线协议彩图壁纸挂画,非常棒哦!

pytorch geometric torch-scatter和torch-sparse安装报错问题解决

Ten security measures against unauthorized access attacks

clickhouse原生監控項,系統錶描述

asp. Net core JWT delivery
随机推荐
Et la dégradation du modèle de génération de texte? Simctg vous donne la réponse
mysql-批量更新
Fletter nested hell? No, constraintlayout to save!
Test medal 1234
A small step in code change and a big leap in thinking
遇到“word在试图打开文件时遇到错误”怎么办?
ICLR'22 Spotlight | 怎样度量神经网络权重中的信息量?
Use the log server to output the topn of various Apache logs
vim 常用快捷键
Internet of things botnet gafgyt family and backdoor vulnerability exploitation of Internet of things devices
asp. Net core JWT delivery
《ClickHouse原理解析与应用实践》读书笔记(2)
测试媒资缓存问题
The 16th Heilongjiang Provincial Collegiate Programming Contest
两个skyline
3Ds Max 精模obj模型导入ArcGIS Pro (二)要点补充
电子方案开发——智能跳绳方案
Prediction and regression of stacking integrated model
k个一组反转链表
加密与解密以及OpenSSL的应用