当前位置:网站首页>How to solve cross domain problems
How to solve cross domain problems
2022-06-30 12:38:00 【YF-SOD】
jsonp
utilize html in script Scripts do not resolve across domains .
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
function getData(data) {
console.log(data)
}
</script>
<script src="http://localhost:8080"></script>
</body>
</html>Server code
const http = require('http')
const server = http.createServer((req, res) =>
let url = req.url
// Set up 'Access-Control-Allow-Origin': '*' To solve the cross domain
//res.writeHead(200, {
// 'content-type': 'application/json;charset=utf-8',
// 'Access-Control-Allow-Origin': '*'
//})
res.write('getData("hello")')
res.end()
})
server.listen(8080,()=>{
console.log('localhost:8080')
})This will print hello character string , Note the usual get and post The data returned from the request server is ‘getData("hello")' String , Only stay script In order to be js Code execution .
Set request header Access-Control-Allow-Origin:*
For example, the notes in the above figure .
边栏推荐
- Joplin implements style changes
- Swagger2 automatically generates API documents
- 腾讯二面:@Bean 与 @Component 用在同一个类上,会怎么样?
- Mysql中 begin..end使用遇到的坑
- 浏览器播放rtsp视频,基于nodeJs
- 时空预测2-GCN_LSTM
- Map集合
- Swagger2自动生成APi文档
- edusoho企培版纯内网部署教程(解决播放器,上传,后台卡顿问题)
- Apple executives openly "open the connection": Samsung copied the iPhone and only added a large screen
猜你喜欢

实现多方数据安全共享,解决普惠金融信息不对称难题

浏览器播放rtsp视频,基于nodeJs

SuperMap iDesktop 常见倾斜数据处理全流程解析

QT MSVC installation and commissioning

Solve the problem that the server cannot be connected via SSH during reinstallation

Analysis of the whole process of common tilt data processing in SuperMap idesktop

QT implementation dynamic navigation bar

品达通用权限系统(Day 7~Day 8)

海思3559开发常识储备:相关名词全解

List collection
随机推荐
SuperMap iClient3D 11i for Cesium三维场景中图例使用说明
Some commonly used hardware information of the server (constantly updated)
How do different types of variables compare with zero
The website with id 0 that was requested wasn‘t found. Verify the website and try again
60 个神级 VS Code 插件!!
Commands for redis basic operations
海思3559萬能平臺搭建:獲取數據幀修改後編碼
Pharmacy management system
Edusoho enterprise training version intranet only deployment tutorial (to solve the problems of player, upload and background jam)
Redis cache problem
解决numpy.core._exceptions.UFuncTypeError: ufunc ‘add‘ did not contain a loop with signature matchin问题
MySql实现两个查询结果相除
Lvgl widget styles
Splitting e-commerce systems into micro services
Docker安装Mysql8和sqlyong连接报错2058的解决方法[随笔记录]
Linux系统Redis的安装
Essay: Research on smart home scheme
品达通用权限系统(Day 7~Day 8)
Grep match lookup
Introduction to new features of ES6