Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RomainLanz's avatar

Ah perfect, so the problem is on the JavaScript code, as you can see, we don't get good columns. Try the code bellow

$('#country_id').change(function()
{
    $.get('/countries/' + this.value + '/cities.json', function(cities)
    {
        var $state = $('#state');
        $state.find('option').remove().end();

        $(cities).each(function(city) {
            $state.append('<option value="' + city.cityID + '">' + city.cityNAME + '</option>');
        });
    });
});
JackD's avatar

still the same i think you forgot the .json in /cities to add i tried to add that but still undefined list after selecting country

RomainLanz's avatar

still the same i think you forgot the .json in /cities

Wrong copy/paste, I've edited.

I think that my each block is wrong. Try that:

$('#country_id').change(function()
{
    $.get('/countries/' + this.value + '/cities.json', function(cities)
    {
        var $state = $('#state');
        $state.find('option').remove().end();

        $.each(cities, function(index, city) {
            $state.append('<option value="' + city.cityID + '">' + city.cityNAME + '</option>');
        });
    });
});
1 like
JackD's avatar

BINGO! thank you so much

1 like
RomainLanz's avatar

Last question for you @dinis, did you understand what we have done or do you need more information?

RomainLanz's avatar

@blackbird Yes haha but I'll shortly change my username, so I'm going to not be A to Z anymore haha :(

bobbybouwmann's avatar

Hehe, that's a lot of threads...

@AtoZ What will your new username be? :P Then I will still call you AtoZ ;)

RomainLanz's avatar

@blackbird

If the other account, with the username I want, will be deleted I'll have @RomainLanz.

If not, I don't know if I stay with @AtoZ or use my other username, @SlyK.

EDIT: Nice, I've a notification because I mentioned myself :P

JackD's avatar

@RomainLanz haha yeah i understand and learned new on what you post.. is it ok that i have that kind of json response available to anyone who will view the console of browser? or is there a way to hide that json response not available for direct access?

RomainLanz's avatar

@dinis Yes, everyone enter the URL on the browser can see the JSON. If you really want to hide that information, you can provide a token only available for 1 query on use it to fetch these data.

1 like
Previous

Please or to participate in this conversation.