当前位置:网站首页>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)
})
边栏推荐
- Auto-created primary key used when not defining a primary key
- 1-3 使用SQL管理数据库
- [grade evaluator] how to register a grade evaluator? How many passes?
- 侧睡哈哈哈哈
- MySQL batch update
- How to move forward when facing confusion in scientific research? How to give full play to women's advantages in scientific research?
- How to run jenkins build, in multiple servers with ssh-key
- 针对美国国家安全局“酸狐狸”漏洞攻击武器平台的分析与应对方案建议
- 【等级测评师】等级测评师怎么报名?多少分及格?
- How to run jenkins build, in multiple servers with ssh-key
猜你喜欢

文本生成模型退化怎麼辦?SimCTG 告訴你答案

Multi table operation - foreign key constraint

Arcmap|assign values to different categories of IDS with the field calculator

Iclr'22 spotlight | how to measure the amount of information in neural network weights?

jenkins下载插件下载不了,解决办法

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

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

How to move forward when facing confusion in scientific research? How to give full play to women's advantages in scientific research?

It is urgent for enterprises to protect API security

jupyterbook 清空控制台输出
随机推荐
Move blog to CSDN
Electronic scheme development - Intelligent rope skipping scheme
Oprator-1 first acquaintance with oprator
变异系数法matlab代码[通俗易懂]
Ssh server configuration file parameter permitrootlogin introduction
企业保护 API 安全迫在眉睫
Coefficient of variation method matlab code [easy to understand]
jupyterbook 清空控制台输出
申请Vector 总线协议彩图壁纸挂画,非常棒哦!
jupyter notebook/lab 切换conda环境
MySQL batch update
Dm8: generate DM AWR Report
本地浏览器打开远程服务器上的Jupyter Notebook/Lab以及常见问题&设置
ArcGIS construction and release of simple road network data service and rest call test
Go build server Foundation
【等级测评师】等级测评师怎么报名?多少分及格?
Zaah Sultan looks at the old driver
Introduction of 3D Max fine model obj model into ArcGIS pro (II) key points supplement
Why have the intelligent investment advisory products collectively taken off the shelves of banks become "chicken ribs"?
《ClickHouse原理解析与应用实践》读书笔记(3)