[eluser]RobertB.[/eluser]
View (vSelector_view)
Code:
$(document).ready(function() {
$('#item').change(function(){
var item = $('#item').val();
//alert(item);
$.ajax({
url: "vSelector/ajax",
type: "POST",
dataType: "json",
success: function (response){
alert(response.element);
//$('#' + response.element).append(response.output);
}
});
});
});
<?=form_open('vSelector', $form_data)?>
<div class="span-7">
<select id="item" name="Item">
<option value="-">-</option>
<?php foreach($items as $row => $item): ?>
<option value="<?=$item->item_id?>"><?=$item->item?></option>
<?php endforeach; ?>
</select>
</div>
<?=form_close()?>
Controller (vSelector)
Code:
function __construct()
{
parent::__construct();
$this->load->model('vSelector_model', 'vSelector');
}
function ajax()
{
$item = $this->input->post('item');
$data['objects'] = $this->vSelector->getObjects($item);
$output['output'] = '';
foreach($data['objects'] as $key => $object){
$data['output'] .= '<option value="'.$object->objectId.'">'.$object->object.'</option>';
}
$data['element'] = 'object';
echo json_encode($data);
}
The only way that I can get an alert is if I comment out.
Controller (vSelector)
Code:
function __construct()
{
parent::__construct();
$this->load->model('vSelector_model', 'vSelector');
}
function ajax()
{
$item = $this->input->post('item');
# $data['objects'] = $this->vSelector->getObjects($item);
# $output['output'] = '';
# foreach($data['objects'] as $key => $object){
# $data['output'] .= '<option value="'.$object->objectId.'">'.$object->object.'</option>';
# }
$data['element'] = 'obj';
echo json_encode($data);
}
Then I will get an alert with "obj"
Obviously this not what I want to do, I'm just trying to understand why is not returning any data or errors.