AJAX retorna json mas não exibe
Boa noite. Estou com problemas pra identificar o porque do código abaixo retornar a mensagem corretamente e não entrar no método success: function(){}
/** Dinamic selects */
$('.call_ajax_on_change').on('change', function(){
/** Define action */
if ($(this).attr('id')==='id_categoria') {
var action = 'action=search_for_sub1&id_categoria=' + $(this).val();
} else if($(this).attr('id')==='id_sub1') {
var action = 'action=search_for_sub2&id_sub1=' + $(this).val();
} else {
var action = 'action=search_for_sub3&id_sub2=' + $(this).val();
}
/** Ajax */
$.ajax({
url: './ajax/dinamic_select.php',
type: 'post',
data: action,
dataType: 'josn',
success: function(callback){
//alert(callback.success);
$.each(callback.success,function(){
/** Interaction and generate values for selects */
/** Read in a select with id id_sub1 */
//if ($(this).attr('id')==='id_categoria') {
alert(callback.success);
$('#id_sub1').prop('disabled', false).html(ret.success);
$('#id_sub2').empty().attr('disabled', true);
$('#id_sub3').empty().attr('disabled', true);
/*}else {
}*/
});
}
});
});
PHP
<?php
/** @package Config.inc.php */
require_once '../_app/Config.inc.php';
/** @var array All data coming from $_POST form */
$post_data = filter_input_array(INPUT_POST, FILTER_DEFAULT);
if($post_data['action']=='search_for_sub1'):
$composer_select_dinamical = new ContentDinamicForSelects();
if($composer_select_dinamical->readSub1($post_data['id_categoria']) != ''):
$array_data = "<option value=\"0\">Selecione</option>";
foreach($composer_select_dinamical->readSub1($post_data['id_categoria']) as $Sub1):
$array_data .= "<option value=\"{$Sub1->id}\">{$Sub1->nome}</option>";
endforeach;
$success = ['success' => $array_data];
echo json_encode($success);
else:
$success = ['success' => '<option value="0">Nenhuma sub de nível 1 encontrada</option>'];
echo json_encode($success);
endif;
endif;Discussão (2)
Carregando comentários...