私はajax + phpが初めてです。その値に応じて別の選択を設定する選択入力があります。
これはhtmlです:
<tr>
<td><label>Categoría: </label></td>
<td><select id="cmbCategorias" onchange="cmbTareas(document.getElementById('cmbCategorias').value);">
<?php
require_once('dataaccess.php');
$categorias = new legajos();
$categorias->cmbCategorias();
?>
</td>
<td><label>Tarea: </label></td>
<td><div id="divTareas"></div></td>
</tr>
これは私のJavaScript関数です:
function cmbTareas(categoria_id) {
document.getElementById("loadingimage").style.display = "block";
document.getElementById("divTareas").innerHTML = "";
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("divTareas").innerHTML = xmlhttp.responseText;
document.getElementById("loadingimage").style.display = "none";
}
}
xmlhttp.open("GET", "legajos_tareas.php?categoria_id="+categoria_id, true);
xmlhttp.send();
}
legajos_tareas.php
require_once('dataaccess.php');
$categoria_id=$_GET['categoria_id'];
$tareas = new legajos();
$tareas->cmbTareas($categoria_id);
dataaccess.php
public function cmbTareas($categoria_id) {
$con = $this->conectarDB();
$query = "CALL SPR_TAREAS(".$categoria_id.")";
$result = $this->con->query($query);
echo '<select id="cmbTareas">';
while ($row = $this->con->fetch($result)) {
echo '<option value="'.$row['ID'].'">'.$row['NOMBRE'].'</option>';
}
echo '</select>';
$this->con->close();
}
初めてだけ完璧に機能します。次に、選択リストで別の項目を選択しても、何も起こりません。Chrome でこのエラーが発生します: Uncaught TypeError: オブジェクトは関数ではありません。オンチェンジ
何か案は?前もって感謝します。