如何修复跨源请求仅支持协议方案:http,数据,chrome,chrome-extension,https [英] How to fix cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https
本文介绍了如何修复跨源请求仅支持协议方案:http,数据,chrome,chrome-extension,https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
i使用记事本来练习HTML和JQuery和Json
我的HTML
hi
i use notepad to practice HTML and JQuery And Json
my HTML
<pre><!DOCTYPE html>
<html lang="en">
<head>
<title>گالری سگ ها</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div id="menu">
<button href="json.json">json</button>
</div>
<div id="frame">
</div>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
我的css:
my css:
* {
font-family: 'Times New Roman', Times, serif;
font-size: 100%;
margin: 0;
padding: 0;
font-weight: normal;
font-style: normal;
box-sizing: border-box;
}
.clear:after {
clear: both;
display: table;
content: "";
}
.clear {
zoom: 1;
}
ul,
ol,
li {
list-style: none;
display: block;
}
div {
display: block;
margin: 0px;
padding: 0px;
}
a {
display: block;
text-decoration: none;
}
body {
background-color: #fff;
}
#menu {
width: 75%;
margin: auto;
background-color: yellow;
}
#menu button {
border: 2px solid blue;
color: white;
background-color: blue;
margin: 3px;
padding: 8px;
}
#frame {
width: 75%;
height: 700px;
border: 1px solid black;
margin: auto;
}
我的json文件位于Html文件的同一目录中:
my json file is in same directory of Html file :
{
"employees": [
{ "firstName": "John", "lastName": "Doe" },
{ "firstName": "Anna", "lastName": "Smith" },
{ "firstName": "Peter", "lastName": "Jones" }
]
}
和我的Jquer代码:
and my Jquer Code:
$(Document).ready(function() {
$('#menu button').click(function() {
var linked = $(this);
var textlinked = linked.attr('href');
$.ajax({
url: textlinked,
success: function() {
alert();
}
});
return false;
});
});
当我运行索引文件时
我收到错误:
when i run my index file i Get error :
jquery-3.2.1.min.js:4 XMLHttpRequest cannot load file:///C:/Users/PC-01/Desktop/vs%20code/HtmlCSS/json.json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
我如何解决这个错误
我尝试过:
i不知道该怎么办?
How Can i solved this error
What I have tried:
i don't know what can i do for this problem
推荐答案
(文件).ready( function (){
(Document).ready(function() {
(' #menu button')。点击(功能(){
var 已关联=
('#menu button').click(function() { var linked =
( this );
var textlinked = linked.attr(' href');
(this); var textlinked = linked.attr('href');
这篇关于如何修复跨源请求仅支持协议方案:http,数据,chrome,chrome-extension,https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文