|
发表于 2021-4-18 23:05:05
|
显示全部楼层
跨域了,ip地址对不上。仔细一看 你不只是ip对不上 协议都对不上
连个服务都不开 看看你的报错 window.onload (file:///D:。。。) file协议你这也叫学web吗 至少得是http://127...才叫运行web
用vscode插件或者nodejs或者python命令可以解决
nodejs脚本我自己写的你可以用用
- const port = 27016,
- url = require("url"),
- fs = require("fs"),
- http = require("http"),
- path = require("path");
- http.createServer((req, res) => {
- let pathname = __dirname + url.parse(decodeURIComponent(req.url)).pathname;
- if (path.extname(pathname) == "") {
- pathname += "/";
- }
- if (pathname.charAt(pathname.length - 1) == "/") {
- pathname += "index.html";
- }
- fs.exists(pathname, exists => {
- if (exists) {
- switch (path.extname(pathname)) {
- case ".html":
- res.writeHead(200, { "Content-Type": "text/html" });
- break;
- case ".js":
- res.writeHead(200, { "Content-Type": "text/javascript" });
- break;
- case ".css":
- res.writeHead(200, { "Content-Type": "text/css" });
- break;
- case ".gif":
- res.writeHead(200, { "Content-Type": "image/gif" });
- break;
- case ".jpg":
- res.writeHead(200, { "Content-Type": "image/jpeg" });
- break;
- case ".png":
- res.writeHead(200, { "Content-Type": "image/png" });
- break;
- default:
- res.writeHead(200, { "Content-Type": "application/octet-stream" });
- }
- fs.readFile(pathname, function (err, data) {
- res.end(data);
- });
- } else {
- res.writeHead(200, { "Content-Type": "text/html" });
- fs.readFile('404.html', function (err, data) {
- if(err){
- res.writeHead(404, { "Content-Type": "text/html" });
- res.end("<h1>404 Not Found</h1>");
- }
- res.end(data);
- });
- }
- });
- }).listen(port, "127.0.0.1");
- console.log(`Server running at http://127.0.0.1:${port}/`);
复制代码
python命令 一样的
|
|