gpt4 book ai didi

javascript - 在 PHP 文件中运行 JS 脚本不起作用

转载 作者:行者123 更新时间:2023-12-02 14:03:53 26 4
gpt4 key购买 nike

当数据插入表中时,我试图将 webhook 发送到我的不和谐服务器,但是该函数没有被调用...目前它只是回显“sendlog()”,如下所示: http://prntscr.com/cxqgk5

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

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

if(mysqli_connect_errno()){
echo(mysqli_connect_error());
}

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

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

<script>
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>
</body>

最佳答案

java脚本函数应该包裹在脚本标签内

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

或者

<?php

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

?>

关于javascript - 在 PHP 文件中运行 JS 脚本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40198759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com