私はJQuery、AJAX、PHPに関する限り初心者であり、新しいmysqlレコードの初期データを提供する連鎖選択を使用してフォームを作成しようとしています。JQueryチェーン選択リモートプラグインをダウンロードしましたが、2番目の選択ドロップダウンでデータを返す方法がわかりません。最初のドロップダウンは別の関数を使用して入力され、ユーザーがこのドロップダウンから値を選択したときに、その値を2番目のドロップダウンの検索文字列として使用する必要があります。 メインフォームのコードスニペットは次のとおりです。
<?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();
}