Может ли кто-нибудь просмотреть мой код и посмотреть, что вызывает второе падение, чтобы не заселяться? Я не совсем понимаю, почему. Заранее спасибо.Раскрывающийся список ajax
Вид:
<div id="finder">
<div class="form">
<select id="brand" name="brand" onchange="myFunction()" >
<option value=""> - Printer Brand - </option>
<?php foreach ($categories as $category_1) { ?>
<?php if ($category_1['category_id'] == $category_id) { ?>
<option value="<?php echo $category_1['category_id']; ?>" selected="selected"><?php echo $category_1['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $category_1['category_id']; ?>"><?php echo $category_1['name']; ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
<br>
<div class="form">
<select name="printerSeries" id="printerSeries">
<option value=""> - Printer Series - </option>
</select>
</div>
<br>
Javascript Ajax вызова
<script type="text/javascript">
function myFunction(){
var brand_id = document.getElementById("brand").value;
\t \t $.ajax({
\t \t url: 'index.php?route=common/home/getSeries&brand_id=' + brand_id,
\t \t type: 'post',
\t \t dataType: 'json',
\t \t success: function(json) {
\t \t \t $('#printerSeries').append('<option value="<?php echo $json['category_id']; ?>" Selected="selected"><?php echo $json['name']; ?></option>');
\t \t
\t \t }
\t \t error: function(){
\t \t \t alert('error');
\t \t } \t \t
\t });
}
</script>
Вот функция контроллера, который принимает запрос JSon
public function getSeries($brand){
$brand_id = $_POST['brand_id'];
$json = array();
$categories_2 = $this->model_catalog_category->gettoner($brand_id);
foreach ($categories_2 as $category_2) {
$json = array(
'category_id' => $category_2['category_id'],
'name' => $category_2['name'],
);
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}