所以我遇到了这个错误,一直在网上找个运气不好的人。任何人都看不到我的代码中的任何失败或有解决此问题的方法。
错误消息: CORS已阻止从源“ null”访问“ FILE_PATH / legg_til_trening.php?dato = 1&situps = 1&armhevninger = 1&situpsOgArmhevninger = 11&planken = 1&bicepsCurls = 1&loping = 1”处的XMLHttpRequest政策:跨源请求仅支持以下协议方案:http,数据,chrome,chrome扩展名,https。
::selection {
background-color: black;
color: white;
}
body {
width: 100%;
max-width: 100%;
margin: 0 auto;
padding: 0;
background-color: orange;
font-family: 'Roboto', sans-serif;
}
/*HEADER*/
header {
position: sticky;
max-width: 80%;
margin: 0 auto;
top: 0;
background-color: white;
border-radius: 0 0 100px 100px;
}
header nav {
width: 85%;
margin: auto;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-around;
padding: 10px 0;
}
header nav a {
color: black;
font-size: 25px;
text-decoration: none;
font-weight: bolder;
padding: 0;
transition: color 0.3s;
font-variant: small-caps;
}
header nav a:hover {
color: orange;
}
/*MAIN*/
main {
width: 80%;
margin: 0 auto;
padding: 20px 0;
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-between;
}
main select {
margin: 10px 0;
border: 1px solid white;
color: black;
padding: 2px;
font-weight: bolder;
}
main section h1 {
margin: 0 10px 10px 0;
color: white;
padding: 0;
font-variant: small-caps;
}
main section table {
table-layout: fixed;
width: 100%;
border-collapse: collapse;
border: 1px black solid;
background-color: white
}
main section table tr:first-of-type {
border: 1px black solid;
padding: 10px;
}
main section table tr th {
border: 1px black solid;
padding: 5px 0;
font-weight: bolder;
}
main section table tr th input {
width: 90%;
padding: 5px;
border: none;
}
main section button {
width: 100%;
margin: 10px auto;
padding: 10px;
border: 1px solid white;
border-radius: 7.5px;
background-color: white;
font-size: 20px;
font-weight: bolder;
cursor: pointer;
transition: color 0.3s;
font-variant: small-caps;
}
main section button:hover {
border: 1px solid white;
background-color: white;
color: orange;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Trening</title>
<link rel="stylesheet" href="css/css_legg_til_trening.css">
<script type="text/javascript">
window.onload = oppstart;
var datalaster;
function oppstart() {
document.getElementById("legTilTrening").onclick = meldPaa;
}
function meldPaa() {
datalaster = new XMLHttpRequest();
var dato = document.getElementById("datoInput").value;
var situps = document.getElementById("situpsInput").value;
var armhevninger = document.getElementById("armhevningerInput").value;
var situpsOgArmhevninger = document.getElementById("situpsInput").value + document.getElementById("armhevningerInput").value;
var planken = document.getElementById("plankenInput").value;
var bicepsCurls = document.getElementById("bicepsCurlsInput").value;
var loping = document.getElementById("lopingInput").value;
var filnavn = "php/legg_til_trening.php?dato=" + dato + "&situps=" + situps + "&armhevninger=" + armhevninger + "&situpsOgArmhevninger=" + situpsOgArmhevninger + "&planken=" + planken + "&bicepsCurls=" + bicepsCurls + "&loping=" + loping;
datalaster.open("GET",filnavn,true);
datalaster.onreadystatechange = ferdigLastet;
datalaster.send();
}
function ferdigLastet() {
if( datalaster.readyState === 4 && datalaster.status === 200) {
alert("Trening lagt til")
}
}
</script>
</head>
<body>
<header>
<nav>
<a href="index.html">Trenings tabell</a>
<a href="legg_til_trening.html">Legg til trening</a>
<a href="endre_trening.html">Endre trenings tabell</a>
</nav>
</header>
<main>
<section>
<h1>Januar:</h1>
<table>
<tr>
<th>Dato:</th>
<th>Situps:</th>
<th>Armhevninger:</th>
<th>Planken (minutter):</th>
<th>Biceps curls pr. arm (vektvest):</th>
<th>Løping (km) (Løpe-/gåmaskin):</th>
</tr>
<tr>
<th><input id="datoInput" type="text" name="" value=""></th>
<th><input id="situpsInput" type="text" name="" value=""></th>
<th><input id="armhevningerInput" type="text" name="" value=""></th>
<th><input id="plankenInput" type="text" name="" value=""></th>
<th><input id="bicepsCurlsInput" type="text" name="" value=""></th>
<th><input id="lopingInput" type="text" name="" value=""></th>
</tr>
</table>
<button id="legTilTrening" type="button" name="button">Legg til trening</button>
</section>
</main>
</body>
</html>