[英]Jquery ajax get data from localhost (json)
I started to work on the Website for our FiveM Server today and want to get the data of a .json
file, which is located on our server, from our server.我今天开始在网站上为我们的 FiveM 服务器工作,并希望从我们的服务器获取位于我们服务器上的
.json
文件的数据。 The problem is, that i can't get get access to the local file from our server... Im working on this since hours and can't find a solution for this problem.问题是,我无法从我们的服务器访问本地文件...我从几个小时以来一直在研究这个问题,但找不到解决这个问题的方法。
Console Error:控制台错误:
Access to XMLHttpRequest at 'http://45.91.251.46:30120/dynamic.json' from origin 'http://45.91.251.46' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Javascript / JQuery Javascript / JQuery
$(function() {
$(document).ready(function () {
$.ajax({
type : "GET",
url: "http://45.91.251.46:30120/dynamic.json",
dataType: "json",
success: function (data) {
console.log(data[0].clients + " " + data[0].sv_maxclients);
}
});
});
});
I would appreciate any type of help <3我将不胜感激任何类型的帮助 <3
i have had this issue when testing ajax calls alot, and the solution i found easiest when using localhost is to download an exstention called "CORS Everywhere"我在测试 ajax 调用很多时遇到了这个问题,我发现使用 localhost 时最简单的解决方案是下载一个名为“CORS Everywhere”的扩展
You can then tell it to unblock CORS for certain websites, i only use it for localhost.然后你可以告诉它为某些网站解锁 CORS,我只将它用于本地主机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.