getJson is not working

Asked

Viewed 222 times

0

I think there’s a problem here: api/combobox_cidades.php?search=, if I put the php file combobox_cidades.php in the main folder (writing only: $.getJSON('combobox_cidades.php?search='), works. now if I leave in the folder api/meuarquivo.php and redirect to it, it doesn’t work.

this javascript is in the folder js/main.js

$('#cod_estados').on('change',function(){
    var valor = $(this).val(); 

    if( valor ) {
        $.getJSON('api/combobox_cidades.php?search=',{cod_estados: $(this).val(), ajax: 'true'}, function(resultado){
            var options = '<option value=""></option>';

            for (var i = 0; i < resultado.length; i++) {
                options += '<option value="' + resultado[i].cod_cidades + '">' + resultado[i].nome + '</option>';
            }
            $('#cod_cidades').html(options).show();
        });
    } else {
        $('#cod_cidades').html('<option value="">– Escolha um estado –</option>');
    }
});

i have a query that fills the data inside a field and it works, I passed the url right as I did in the previous one and it works.

//preenche os dados para o campo select
$.ajax({
    dataType: 'json',
    cache: false,
    url: 'api/especialidade.php',
    success: function(retorno){
        for(var i=0;i <retorno.length; i++){
            $('td select#cod_especialidade').append("<option value='"+retorno[i].cod_especialidade+"'>"+retorno[i].nome+"</option>");
        }
    }
});
  • Already tried a path relative to the root? /api/...?

  • Do you have it online? try this browser address URL directly until it works, and test what bfavaretto suggested. Comment here on whether it worked.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.