Aurelia 如何解决;TypeError:尝试获取资源时出现NetworkError;
当我使用aurelia fetch client将json数据发布到服务器时,我得到了这样一个错误“TypeError:NetworkError当试图获取资源时”。我认为您的答案对我非常有用Aurelia 如何解决;TypeError:尝试获取资源时出现NetworkError;,aurelia,Aurelia,当我使用aurelia fetch client将json数据发布到服务器时,我得到了这样一个错误“TypeError:NetworkError当试图获取资源时”。我认为您的答案对我非常有用 post.html <template> <section> <form role="form" submit.trigger="signup()"> <div class="form-group"> <label fo
post.html
<template> <section> <form role="form" submit.trigger="signup()"> <div class="form-group"> <label for="OrganisationId">OrganisationId</label> <input type="text" value.bind="organisationId" placeholder="OrganisationId"> </div> <div > <label for="OrganisationName">OrganisationName</label> <input type="OrganisationName" value.bind="organisationName" placeholder="Password"> </div> <button type="submit" class="btn btn-default">Enter</button> </form> </section> </template>
Chrome.exe--user data dir=“C:/Chrome dev session”--禁用web安全性
,并查看您是否可以在该环境中运行代码。这将允许访问“access control allow origin”标头请求
我试着在Chrome、Firefox和Edge中正常运行你的部分代码,但得到了相同的CORS错误。但是当我使用上述命令时,它确实运行了。你没有提供太多的信息,但你可能需要在服务器端和代码中做一些更改
上面的命令以及有关CORS的更多信息可在此处找到,因此:
希望这至少能为您指明正确的方向。我的感觉是,它可能与CORS无关。它可能需要处理“导入”机制(?) 以下是我的案例:我刚将OpenLayers的本地版本更新到v5.0.0时收到一条“源代码映射错误”消息。以下是我的html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lignes SNCF</title>
<link rel="stylesheet" href="sncf.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/openlayers/5.0.0/ol.css">
<link rel="preload" href="Gares.json">
<link rel="preload" href="communes.geojson">
<script src="../../../ENSEIGNEMENT/v5.0.0-dist/ol.js"></script>
</head>
<body>
<h1>Lignes SNCF</h1>
<div id="canvasMap" class="map"><div id="popup"></div></div>
<script src="./sncfV5.js"></script>
</body>
</html>
令人费解的是,JavaScript代码工作正常,映射正确地显示在屏幕上,甚至在控制台上出现“源映射错误”消息之前
如果我回到以前版本的OpenLayers,唯一的区别是:
<script src="../../../ENSEIGNEMENT/v4.6.5-dist/ol.js"></script>
而不是:
import Map from 'ol.Map.js';
const map = new Map(...);
我不知道该怪什么,但“Suresh”最初的问题也与“进口”有关机制。在我的案例中,我看不到CORS的意义。在我的案例中,这是一个CORS问题,POST请求被阻止,因为服务器没有在允许的标头请求标头中列出所有需要的标头。在服务器上将“访问控制允许标头”设置为“*”就成功了
<script src="../../../ENSEIGNEMENT/v4.6.5-dist/ol.js"></script>
const map = new ol.Map(...);
import Map from 'ol.Map.js';
const map = new Map(...);