就 JQuery、AJAX 和 PHP 而言,我是新手,我正在尝试构建一个带有链式选择的表单,该表单将为新的 mysql 记录提供初始数据。我已经下载了 JQuery 链式选择远程插件,对于我来说,我无法弄清楚如何获取第二个选择下拉列表返回的数据。第一个下拉列表使用另一个函数填充,当用户从此下拉列表中选择一个值时,我希望该值用作第二个下拉列表的搜索字符串。 主窗体的代码片段是:
<?php
<head>
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="../js/jquery.chained.remote.js" charset="utf-8"></script>
</script>
<script type="text/javascript">
$('#series').remoteChained("#series", "../models/json.php");
</script>
</head>
<body>
<form action="" method="post">
<table border="1">
<tr>
<th>Season:</th>
<td><select name="season" id="mark">
<option value="">Select Season...</option>
<?php
$i = 0;
while ($i < count($showseason)){ // obtain seasons from getseason() function
?>
<option value="<?php echo $showseason[$i]; ?>">
<?php echo $showseason[$i]; ?> </option>
<?php
$i++;
} ?>
</select></td>
<th>Competition:</th><td><select name="competition" id="series">
<option value="">Competition type...</option>
</select></td>
以下是Mysql select(json.php)的代码
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/helpers.inc.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/db_connect.php';
try
{
$result = $pdo->prepare("SELECT sideid, competition FROM pennantsides");
$result->execute();
echo json_encode($result->fetchAll(PDO::FETCH_ASSOC));
}
catch (PDOException $e)
{
$output = 'Error selecting records - Please contact your Site Administrator';
include $_SERVER['DOCUMENT_ROOT'] . '/views/output.html.php';
exit();
}