Discord Webhooks - 没有回应

I need help, my Webhook isn't responding back to the Discord to post a message of a log. Here is the code, I removed some of it for security reasons..

<?php
        ?>
        <script type="text/javascript">
function sendLog(){ 
    tosend = [
    '**Server added;**',
    'Game Name: <?php echo(json_encode($name)); ?>',
    'Game ID: <?php echo(json_encode($gid)); ?>',
    'Server ID: <?php echo(json_encode($sid)); ?>',
    ],
    msgJson = {
         "attachments": [
        {
            "color": "#CC09EF",
            "text": tosend.join('
'),
            "footer": "Infius Game Logs",
            "footer_icon": "http://deersystems.net/assets/images/nfius.png",
        }
    ]
        }
  post(hookurl, msgJson); 
  }

function post(url, jsonmsg){
    xhr = new XMLHttpRequest();
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-type", "application/json");
    var data = JSON.stringify(jsonmsg);
    xhr.send(data);
    xhr.onreadystatechange = function() {
        if(this.status != 200){
            alert("ttt");
        }
    }
}
</script>

<?php
        if($token == '*****'){
        $con = mysqli_connect("localhost","8888888");

        if(mysqli_connect_errno()){
            echo(mysqli_connect_error());
        }
        } elseif($type == 'add' and $sid !=NULL and $gid !=NULL and $name!=NULL and $players !=NULL){
        ?>
        <script type="text/javascript">
                sendLog();
        </script>
        <?php

} else {

echo"<script type=\"text/javascript\">
    sendLog();
    </script>";
}
    ?>

I don't think the function is being called with http Post Async, or the Js is not loading.