gpt4 book ai didi

javascript - 选择第一个选择框后,根据第一个选择结果显示第二个结果。但 POST 时没有得到任何结果

转载 作者:行者123 更新时间:2023-12-03 08:42:21 25 4
gpt4 key购买 nike

选中第一个选择框后,根据第一个选择结果显示第二个结果。但 POST 时没有得到任何结果。当我提交表单时,系统提示

"Notice: Undefined index: location in C:\xampp\htdocs\auditsystem\calendar\func\scheduleaction.php on line 8"

我在显示时得到结果,仅在提交表单时显示错误。

func.php

 <?php
include_once('db.php');
function getTierOne()
{
$result = mysql_query("SELECT DISTINCT * FROM outlet_type")
or die(mysql_error());

while($tier = mysql_fetch_array( $result ))

{
echo '<option value="'.$tier['id'].'">'.$tier['type'].'</option>';
}
}

if(isset($_GET['func'])) {
drop_1($_GET['drop_var']);
}

function drop_1($drop_var)
{

$result2 = mysql_query("SELECT DISTINCT * FROM outlet_type_location WHERE outlet_type_id='$drop_var'")
or die(mysql_error());

echo '<select name="location" id="tier_one" onChange="showUP(this.value)" class="form-control">
<option value=" " disabled="disabled" selected="selected">-Select Outlet location-</option>';
while($drop_2 = mysql_fetch_array( $result2 ))
{
echo '<option value="'.$drop_2['location'].'">'.$drop_2['location'].'</option>';
}
echo '</select> ';

}
?>

scheduleaction.php(此处显示错误代码)

<?php

include_once("db.php");

$auditor_id = $_POST["auditor"];
$outlet_type_id = $_POST["type"];
$date = $_POST["date"];
$outlet_location = $_POST["location"];


echo $auditor_id."<br>";
echo $outlet_type_id."<br>";
echo $outlet_location;
echo $date;
?>

PHP 表单

       <script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#drop_1').change(function(){
$('#wait_1').show();
$('#result_1').hide();
$.get("func/func.php", {
func: "drop_1",drop_var: $('#drop_1').val()
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 0);
});
return false;
});
});

function finishAjax(id, response) {
$('#wait_1').hide();

$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
<tr>
<label>Oulet Type:</label>
<select name="type" id="drop_1" class="form-control">
<option value="" selected="selected" disabled="disabled">-Click to select-</option>
<?php

include ("func/db.php");
include ("func/func.php");

getTierOne();

?>
</select>
<span id="wait_1" style="display: none;"><img alt="Please Wait" src="ajax-loader.gif"/></span>
<span id="result_1" style="display: none;"></span>
</tr>

最佳答案

尝试一下,唯一的错误是,include()出现在表单之外。

<?php
session_start();
include ("../connection/connect.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Apex Audit System | Administration Panel</title>
<!-- Core CSS - Include with every page -->
<link href="../assets/plugins/bootstrap/bootstrap.css" rel="stylesheet" />
<link href="../assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
<link href="../assets/plugins/pace/pace-theme-big-counter.css" rel="stylesheet" />
<link href="../assets/css/style.css" rel="stylesheet" />
<link href="../assets/css/main-style.css" rel="stylesheet" />
<!-- Page-Level CSS -->
<link href="../assets/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#drop_1').change(function(){
$('#wait_1').show();
$('#result_1').hide();
$.get("func/func.php", {
func: "drop_1",drop_var: $('#drop_1').val()
}, function(response){
$('#result_1').fadeOut();
setTimeout("finishAjax('result_1', '"+escape(response)+"')", 0);
});
return false;
});
});

function finishAjax(id, response) {
$('#wait_1').hide();

$('#'+id).html(unescape(response));
$('#'+id).fadeIn();
}
</script>
<body>

<?php
include_once("../assets/template/mainlinks2.php");
include_once("../assets/template/sidebar3.php");
?> <!-- page-wrapper -->
<div id="page-wrapper">


<div class="row">
<!-- page header -->
<div class="col-lg-12">
<h1 class="page-header">Setup New Schedule</h1>
</div>
<!-- end page header -->
</div>
<div class="row">
<div class="col-lg-12">
<!-- Advanced Tables -->
<div class="panel panel-default">
<div class="panel-heading">
Assign New Schedule
</div>
<div class="panel-body">
<div class="table-responsive">

<form action="func/scheduleaction.php" role="form" method="POST" name="form">
<table>
<div class="form-group">

<?php

include ("func/db.php");
include ("func/func.php");
?>
<tr>
<label>Auditor Name:</label>
<select class="form-control" name="auditor">
<?php
$result = $db->query("SELECT * FROM auditor");
while($row = mysqli_fetch_array($result))
{
echo '<option value="'.$row["id"].'">'.$row["auditor_name"].'</option>';
}
echo "</select>";
?>
</tr>


<tr>
<label>Oulet Type:</label>
<select name="type" id="drop_1" class="form-control">
<option value="" selected="selected" disabled="disabled">-Click to select-</option>
<?php

getTierOne();

?>
</select>
<span id="wait_1" style="display: none;"><img alt="Please Wait" src="ajax-loader.gif"/></span>
<span id="result_1" style="display: none;"></span>
</tr>

<tr>
<label>Audit Date:</label>
<input type="date" name="date" class="form-control" required="required">
</tr>
<br>
<tr>
<td><button type="submit" class="btn btn-primary">Submit Button</button></td>
<td><button type="reset" class="btn btn-success">Reset Button</button></td>
</tr>

</div>
</form>
</table>
</div>

</div>
</div>
<!--End Advanced Tables -->

</div>
</div>
</div>
<!-- end page-wrapper -->

</div>
<!-- end wrapper -->


<!-- Core Scripts - Include with every page -->
<script src="../assets/plugins/jquery-1.10.2.js"></script>
<script src="../assets/plugins/bootstrap/bootstrap.min.js"></script>
<script src="../assets/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="../assets/plugins/pace/pace.js"></script>
<script src="../assets/scripts/siminta.js"></script>

</body>

</html>

关于javascript - 选择第一个选择框后,根据第一个选择结果显示第二个结果。但 POST 时没有得到任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33011365/

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