2016-10-23 4 views
0

データがテーブルに挿入されたときに不具合サーバーにウェブフックを送信しようとしていますが、その機能は呼び出されていません...現在、 "sendlog() 「ここに示したように:http://prntscr.com/cxqgk5PHPファイルでJSスクリプトを実行していない

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

答えて

2

Javaスクリプト機能は、スクリプトタグ内にラップする必要があります

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

OR

<?php 

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

?> 
0

あなたは出力sendLog()を持っています。ありません。スクリプトタグですので、通常のテキストと見なされます。その関数を呼び出す場合は、スクリプトタグの間で必要です。

また、コードのクリーンな書式設定が必要です。同じページに複数のスクリプトタグを置かないでください。すべてのjsコードを単一スクリプトタグに追加します。

関連する問題