Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 本地网络上的跨来源请求_Javascript_Jquery_Html_Bootstrap 4 - Fatal编程技术网

Javascript 本地网络上的跨来源请求

Javascript 本地网络上的跨来源请求,javascript,jquery,html,bootstrap-4,Javascript,Jquery,Html,Bootstrap 4,我正在尝试一些非常简单的方法,但由于某些原因,它不起作用: index.html: <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>SyriLab</title> <link rel="stylesheet" href="css/bootstrap.min.css"> <link rel="stylesheet" href="

我正在尝试一些非常简单的方法,但由于某些原因,它不起作用:

index.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>SyriLab</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
    <header></header>
    <div id="content"></div>

    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/poper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/functions.js"></script>
    <script src="js/main.js"></script>
</body>
</html>
启动index.html时出现的错误:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>SyriLab</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
    <header></header>
    <div id="content"></div>

    <script src="js/jquery-3.3.1.min.js"></script>
    <script src="js/poper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/functions.js"></script>
    <script src="js/main.js"></script>
</body>
</html>
加载失败file:///E:/Dev/Eclipse/SyriLab/pages/header.html: 跨源请求仅支持协议方案:http、数据、chrome、chrome扩展、https

加载失败file:///E:/Dev/Eclipse/SyriLab/pages/home.html: 跨源请求仅支持协议方案:http、数据、chrome、chrome扩展、https

所有内容都是本地的,相同的根,我只是尝试创建一个基本的html页面,包括引导和jquery(poper也是,不确定它是什么,但在引导页面上)。在php中使用类似于“include”的东西,但使用常规的js和html


我做错了什么?

根据您的问题,您似乎试图以本地文件的形式访问
index.html
。相反,您必须使用webserver(例如nginx、apache等)来访问该文件。jQuery的加载方法将无法加载文件,因为用于访问本地文件的协议是
file://
。由于安全原因,浏览器禁止此类请求


配置Web服务器并尝试使用
http
协议访问
index.html
,您的代码应该可以正常工作。

如其他人所述。您必须使用服务器提供文件

为此,为了避免软件安装,请使用Python

在控制台中键入:

cd /path/to/my/index.html
python -m http.server
默认情况下,它将使用

这个简单的服务器将为您的目录文件提供服务。
Index.html是服务器将尝试查找和服务的空资源请求。

错误告诉您。。。提示您的协议是
文件
。。。安装猫鼬。它是一个用于windows的轻量级web服务器,可以创建一个将组成的域指向本地主机的整个主机。难道没有其他方法吗?我希望能够在不运行任何东西的情况下进行实验。像这样加载外部html是一种非常糟糕的做法。不,我在骗你。去安装猫鼬。。。太简单了。威尔斯:那我该怎么办?好的,谢谢,我只是不想安装或运行任何东西,只想启动我的页面。但是,如果没有其他选择,它会导致
/usr/bin/python:没有名为http
pip install http
的模块出现
错误:找不到满足要求的版本http错误:找不到http
和更早版本的
模块nofounderror:没有名为'request'的模块
。不确定问题是由过时的答案造成的,还是我用
pip做了一些奇怪的事情