我的代码还有另一个问题。
<script type="text/javascript">
$("#wojewodz").change(function(){
var id_wojewodztwa = $("#wojewodz").children(":selected").attr("id");
$.post("miasta.php", { id_wojewodztwa: id_wojewodztwa } );
$('#powiat_miasto_auto_complete').autocomplete({source:'miasta.php', minLength:2});
});
</script>
这是获取所选选择的 ID 并将其传输到 miasta.php 的函数
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
);
try {
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass, $options);
}
catch(PDOException $e) {
echo $e->getMessage();
}
$return_arr = array();
if (($conn) and (isset($_GET['id_wojewodztwa'])))
{
$id_wojewodztwa = $_GET['id_wojewodztwa'];
$ac_term = "%".$_GET['term']."%";
$query = "SELECT DISTINCT nazwa FROM podzial_tm where woj='$id_wojewodztwa' and nazdod!='województwo' and nazwa like :term LIMIT 10";
$result = $conn->prepare($query);
$result->bindValue(":term",$ac_term);
$result->execute();
/* Retrieve and store in array the results of the query.*/
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$row_array['value'] = $row['nazwa'];
array_push($return_arr,$row_array);
}
}
/* Free connection resources. */
$conn = null;
/* Toss back results as json encoded array. */
echo json_encode($return_arr);
?>
有人可以告诉我哪里有错误吗?当我将“ where woj='$id_wojewodztwa'”更改为例如“ where woj='26'”并删除“ and (isset($_GET['id_wojewodztwa']))”时,一切正常,所以我认为我有问题与 POST
复活节快乐!:)))