Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 错误:未捕获引用错误:未在HTMLSelectElement.onchange中定义onChangeAssignedGroup_Javascript_Php_Ajax_Selection_Onchange - Fatal编程技术网

Javascript 错误:未捕获引用错误:未在HTMLSelectElement.onchange中定义onChangeAssignedGroup

Javascript 错误:未捕获引用错误:未在HTMLSelectElement.onchange中定义onChangeAssignedGroup,javascript,php,ajax,selection,onchange,Javascript,Php,Ajax,Selection,Onchange,当用户更改“Assigned to Group”选择中的值时,我在尝试通过javascript调用php脚本时遇到问题。它最终应该会更改尚未创建的“分配给用户”选择的选项列表 我一直收到一个错误,说它无法识别函数名。当我尝试运行一个简单的值更改和警报来验证它是否可以获得值时,它识别了它,并相应地进行了更新。当我添加Ajax命令时,它开始无法识别它。我敢肯定,我可能只是用错了,因为我以前从未使用过ajax。但从我所看到的样本来看,这似乎相当直接 错误:未捕获引用错误:未在HtmlSelect元素上

当用户更改“Assigned to Group”选择中的值时,我在尝试通过javascript调用php脚本时遇到问题。它最终应该会更改尚未创建的“分配给用户”选择的选项列表

我一直收到一个错误,说它无法识别函数名。当我尝试运行一个简单的值更改和警报来验证它是否可以获得值时,它识别了它,并相应地进行了更新。当我添加Ajax命令时,它开始无法识别它。我敢肯定,我可能只是用错了,因为我以前从未使用过ajax。但从我所看到的样本来看,这似乎相当直接

错误:未捕获引用错误:未在HtmlSelect元素上定义onChangeAssignedGroup。onchange

<?php
include('classes/class.User.php');
include('classes/class.Role.php');
include('classes/class.User_Role.php');
include('constants.php');
session_start();
?>
<html>
    <head>
        <link href="style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
        <script>
            function onChangeAssignedGroup() {
                
              var new_assigned_to_role_id = document.getElementById("option_list_assigned_to_role_id").value;
              document.getElementById("assignedGroupId").innerHTML = "You selected: " + new_assigned_to_role_id;
              alert(new_assigned_to_role_id);
              $.ajax({
                  method: "POST",
                  url: "ticket_details.php",
                  data:{
                        ticket_id:$_POST['ticket_id'];
                        creator_user_id:$_POST['creator_user_id'];
                        creator_user_name:$_POST['creator_user_name'];
                        status:$_POST['status'];
                        priority:$_POST['priority'];
                        title:$_POST['title'];
                        assigned_to_role_id:new_assigned_to_role_id;
                        assigned_to_role_name:"";
                        assigned_to_user_id:$_POST['assigned_to_user_id'];
                        assigned_to_user_name:$_POST['assigned_to_user_name'];
                  },
                  success: function () {
                    alert('form was submitted');
                  }
              });
            }
        </script>
    </head>
    <body>
        <p><a href="ticket_overview.php">Return to Tickets</a></p>
        <?php
            
        
            if(isset($_POST['submit']) or isset($_POST['submit_new_comment']) or isset($_POST['submit_update_ticket'])){
                $ticket_id = $_POST['ticket_id'];
                $creator_user_id = $_POST['creator_user_id'];
                $creator_user_name = $_POST['creator_user_name'];
                $status = $_POST['status'];
                $priority = $_POST['priority'];
                $title = $_POST['title'];
                $assigned_to_role_id = $_POST['assigned_to_role_id'];
                $assigned_to_role_name = $_POST['assigned_to_role_name'];
                $assigned_to_user_id = $_POST['assigned_to_user_id'];
                $assigned_to_user_name = $_POST['assigned_to_user_name'];
                //connect to database
                include("database_connection.php");
                
                //handle update to ticket
                if(isset($_POST['submit_update_ticket'])){
                    $update = $mysqli->query("UPDATE `ticket` SET `status` = '$status', `priority` = '$priority', 
                                            `assigned_to_role_id` = '$assigned_to_role_id', `assigned_to_role_name` = '$assigned_to_role_name', 
                                            `assigned_to_user_id` = '$assigned_to_user_id', `assigned_to_user_name` = '$assigned_to_user_name' 
                                            WHERE `ticket`.`id` = $ticket_id");
                    if(!$update){
                        echo"<p>".$mysqli->error."</p>";
                    }
                }
                
                //handle new comment
                if(isset($_POST['submit_new_comment'])){
                    $new_comment = $_POST['new_comment'];
                    $current_id = $_SESSION['user']->getId();
                    $current_username = $_SESSION['user']->getUsername();
                    
                    //sanitize data
                    $new_comment = $mysqli->real_escape_string($new_comment);
                    
                    unset($_POST['submit_new_comment']);
                    //insert new comment into database.
                    $insert = $mysqli->query("INSERT INTO ticket_comment (ticket_id, user_id, user_name, text) VALUES ('$ticket_id', '$current_id', '$current_username', '$new_comment')");
                    if(!$insert){
                        echo"<p>".$mysqli->error."</p>";
                    }
                    
                }
                
                //include arrays for converting values returned
                include("value_maps.php");
                echo "<p id='assignedGroupId'></p>";
                echo "<p>role id:".$assigned_to_role_id."</p>";
                echo "<p>role name:".$assigned_to_role_name."</p>";
                if(in_array($assigned_to_role_id,$_SESSION['user']->getRoles())){
                    echo "<p>you have this role.</p>";
                } else {
                    echo "<p>you don't have this role.</p>";
                }
                print_r($_SESSION['user']->getRoles());
                echo"
                    <form action='' method='post'>
                        <input type='hidden' name='ticket_id' value='$ticket_id'>
                        <input type='hidden' name='creator_user_id' value='$creator_user_id'>
                        <input type='hidden' name='creator_user_name' value='$creator_user_name'>
                        <input type='hidden' name='title' value='$title'>
                        <input type='hidden' name='assigned_to_role_id' value='$assigned_to_role_id'>
                        <input type='hidden' name='assigned_to_role_name' value='$assigned_to_role_name'>
                        <input type='hidden' name='assigned_to_user_id' value='$assigned_to_user_id'>
                        <input type='hidden' name='assigned_to_user_name' value='$assigned_to_user_name'>
                    <table border='0' align='center' cellpadding='5'>
                        <tr>
                            <th>Ticket ID</th>
                            <th>Title</th>
                            <th>Status</th>
                            <th>Priority</th>
                            <th>Assigned To Group</th>
                            <th>Assigned To User</th>
                        </tr>
                        <tr>
                            <td>$ticket_id</td>
                            <td>$title</td>";
                if(in_array($assigned_to_role_id,$_SESSION['user']->getRoles()) or in_array(ROLE_ID_ADMIN,$_SESSION['user']->getRoles())){
                    
                    echo "<td><select name='status'>";
                    $status_index = 0;
                    foreach($status_array as $status_choice){
                        if($status == $status_index){
                            echo "<option value='". $status_index."' selected>". $status_choice ."</option>";
                        } else {
                            echo "<option value='". $status_index."'>". $status_choice ."</option>";
                        }
                        $status_index++;
                    }
                    echo "</select></th>";
                    echo "<td><select name='priority'>";
                    $priority_index = 0;
                    foreach($priority_array as $priority_choice){
                        if($priority == $priority_index){
                            echo "<option value='". $priority_index."' selected>". $priority_choice ."</option>";
                        } else {
                            echo "<option value='". $priority_index."'>". $priority_choice ."</option>";
                        }
                        $priority_index++;
                    }
                    echo "</select></th>";
                } else {
                    echo "<td>".$status_array[$status]."</th>";
                    echo "<td>".$priority_array[$priority]."</th>";
                }
                if(in_array(ROLE_ID_ADMIN,$_SESSION['user']->getRoles())){
                    echo "<td><select id='option_list_assigned_to_role_id' name='assigned_to_role' onchange='onChangeAssignedGroup()'>";
                    foreach($_SESSION['roles'] as $assigned_to_role_choice){
                        if($assigned_to_role_id == $assigned_to_role_choice->getId()){
                            echo "<option value='". $assigned_to_role_choice->getId()."' selected>". $assigned_to_role_choice->getName() ."</option>";
                        } else {
                            echo "<option value='". $assigned_to_role_choice->getId()."'>". $assigned_to_role_choice->getName() ."</option>";
                        }
                    }
                    echo "</select></td>";
                } else {
                    echo "<td>$assigned_to_role_name</td>";
                    echo "<td>$assigned_to_user_name</td>";
                }
                echo"
                        </tr>
                        <tr>
                            <td colspan='5'></td>
                            <td><input type='submit' name='submit_update_ticket' value='Update Ticket Details' required></td>
                        </tr>
                    </table>

                </form>
                ";
                
                //get back ticket details
                $results = $mysqli->query("SELECT `id`,`ticket_id`,`user_id`,`user_name`,`text`,`create_date`,`modify_date` FROM `ticket_comment` WHERE `ticket_id` = ".$ticket_id." ORDER BY `create_date`");
                
                //if insert was successful
                if($results){
                    
                    //header('location:registration_email_sent.php');
                    if ($results->num_rows > 0){
                        echo "
                            <table border='0' align='center' cellpadding='5'>
                                <tr>
                                    <th>Username</th>
                                    <th>Comment</th>
                                </tr>
                                ";
                        while($row = $results->fetch_row()){
                            echo"
                                <tr>
                                    <td>".$row[3].": </td>
                                    <td>".$row[4]."</td>
                                </tr>";
                        }
                    } else {
                        echo "<p>No comments found. </p>";
                    }
                }
                
                $mysqli->close();
                
                echo"
                    <form method='post' action=''>
                        <input type='hidden' name='ticket_id' value='$ticket_id'>
                        <input type='hidden' name='creator_user_id' value='$creator_user_id'>
                        <input type='hidden' name='creator_user_name' value='$creator_user_name'>
                        <input type='hidden' name='status' value='$status'>
                        <input type='hidden' name='priority' value='$priority'>
                        <input type='hidden' name='title' value='$title'>
                        <input type='hidden' name='assigned_to_role_id' value='$assigned_to_role_id'>
                        <input type='hidden' name='assigned_to_role_name' value='$assigned_to_role_name'>
                        <input type='hidden' name='assigned_to_user_id' value='$assigned_to_user_id'>
                        <input type='hidden' name='assigned_to_user_name' value='$assigned_to_user_name'>
                        
                    
                        <table border='0' align='center' cellpadding='5'>
                            <tr>
                                <th>New Comment</th>
                                <th><input type='submit' name='submit_new_comment' value='Post New Comment'></th>
                            </tr>
                            <tr>
                                <td colspan='2'><textarea name='new_comment' rows='10' cols='30' placeholder='New Comment Here' required></textarea></td>
                            </tr>
                        </table>
                    </form>
                ";
            } 
        ?>
        
    </body>
</html>

函数onChangeAssignedGroup(){
var new_assigned_to_role_id=document.getElementById(“选项列表_assigned_to_role_id”)。值;
document.getElementById(“assignedGroupId”).innerHTML=“您选择:”+new\u assigned\u to\u role\u id;
警报(分配给角色id的新角色);
$.ajax({
方法:“张贴”,
url:“ticket_details.php”,
数据:{
票证号:$_POST['ticket_id'];
创建者\用户\ id:$\发布['创建者\用户\ id'];
creator_user_name:$_POST['creator_user_name'];
状态:$_POST['status'];
优先级:$_POST['priority'];
标题:$_POST['title'];
分配给角色标识:新的分配给角色标识;
已将_分配给_角色_名称:“”;
已分配给用户id:$\u POST['assigned\u to\u user\u id'];
分配给用户名称:$\u POST['assigned\u to\u user\u name'];
},
成功:函数(){
警报(“表格已提交”);
}
});
}


在ajax请求的数据对象中,需要用逗号替换分号


您还应始终使用预处理语句与数据库交互。

警告:您完全可以使用参数化预处理语句,而不是手动生成查询。它们由或提供。永远不要相信任何形式的输入!即使您的查询仅由受信任的用户执行。泰,这就是问题所在。我将研究如何使用准备好的语句。谢谢你的提醒!