2016-10-23 2 views
0

Ich versuche einen Webhook an meinen Discord-Server zu senden, wenn Daten in die Tabelle eingefügt werden, die Funktion wird jedoch nicht aufgerufen ... Momentan gibt es nur "sendlog() "wie hier gezeigt: http://prntscr.com/cxqgk5Ausführen eines JS-Skripts in einer PHP-Datei funktioniert nicht

<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
</head> 
 
\t <body> 
 
\t <?php 
 
\t $token = $_POST["token"]; 
 
\t $type = $_POST["type"]; 
 
\t $pid = $_POST["pid"]; 
 
\t $sid = $_POST["sid"]; 
 
\t $gid = $_POST["gid"]; 
 
\t $name = $_POST["name"]; 
 
\t $players = $_POST["players"]; 
 
\t $max = $_POST["max"]; 
 
\t $cdesc = $_POST["cdesc"]; 
 
\t $sus = $_POST["sus"]; 
 

 
\t if($token == 'DS_443'){ 
 
\t \t $con = mysqli_connect("localhost","**","**","**"); 
 

 
\t \t if(mysqli_connect_errno()){ 
 
\t \t \t echo(mysqli_connect_error()); 
 
\t \t } 
 
\t 
 
\t \t if($type == 'edit' and $players !=NULL and $sid !=NULL){ 
 
\t \t \t $con->query("UPDATE OnlineServers SET ServerCurrent='$players' WHERE ServerID='$sid'"); 
 
\t \t } elseif($type == 'remove' and $sid !=NULL){ 
 
\t \t \t $con->query("DELETE FROM OnlineServers WHERE ServerID='$sid'"); 
 
\t \t } elseif($type == 'add' and $sid !=NULL and $gid !=NULL and $name!=NULL and $players !=NULL){ 
 
\t \t \t $con->query("INSERT INTO OnlineServers (GameId,GameName,GameMax,ServerCurrent,ServerID,Command) VALUES ('$gid','$name','$max','$players','$sid','TEST')"); 
 
\t ?> 
 
\t \t \t sendLog(); 
 
\t <?php 
 
\t \t } elseif($type == 'call'){ 
 
\t \t \t $con->query("INSERT INTO Calls  (Caller,CallerID,CallID,CallDesc,Suspect,SuspectID,ServerID,GameID) VALUES     ('$pid','$name','$cdesc','$sus')"); 
 
\t \t }   
 
\t } else { 
 
\t ?> 
 
\t \t sendLog(); 
 
\t <?php 
 
\t } 
 
?> 
 

 
<script> 
 
\t function sendLog(){ 
 
\t \t var hookurl = "webhookurl" 
 
\t \t let tosend = { 
 
\t \t 'Server added;', 
 
\t \t 'Game Name: ', 
 
\t \t 'Game ID: ', 
 
\t \t 'Server ID: ', 
 
\t \t }, 
 
\t \t var msgJson = { 
 
\t \t \t "attachments": [ 
 
\t \t \t \t { 
 
\t \t \t \t "color": "#CC09EF", 
 
\t \t \t \t "text": tosend, 
 
\t \t \t \t "footer": "Infius Game Logs", 
 
\t \t \t \t "footer_icon": "http://deersystems.net/assets/images/nfius.png", 
 
\t \t \t \t } 
 
\t \t \t ] 
 
\t \t } 
 
\t \t post(hookurl, msgJson); 
 
\t } 
 
</script> 
 

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

Antwort

2

Java-Script-Funktion sollte innerhalb Script-Tags

<script type="text/javascript"> 
    sendLog(); 
    </script> 

ODER

<?php 

echo '<script type="text/javascript">', 
    'sendLog();', 
    '</script>' 
; 

?> 
gewickelt werden
0

Sie haben Ausgang SendLog(); ohne Skript-Tag so wird es normalen Text betrachten. Wenn Sie diese Funktion aufrufen möchten, benötigen Sie sie zwischen Skript-Tag.

Auch sollten Sie saubere Formatierung des Codes haben. Und vermeiden Sie mehrere Skript-Tags auf den gleichen Seiten. Fügen Sie den gesamten js-Code in einem einzelnen Skript-Tag hinzu.

Verwandte Themen