简体   繁体   中英

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. 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

$(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

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"

You can then tell it to unblock CORS for certain websites, i only use it for localhost.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM