'Get Selected dropdown options use Axios on laravel 8

now i'm making same project using laravel 8. i integrate AXIOS on it. right now, i not able to get selected dropdown option if function validation detect error input when do submit.

basically, i made code for display state when user select the country. but still confuse how to get selected state when have error on validation.

this is my code

<script>
    $(document).ready(function () {  

        if($('#selectCountry').val() != ""){

            var chooseCountry = $('#selectCountry').val(); 

            axios.post('/getState', {country_id: chooseCountry  }).then(function(res) {  
                $('#selectstate').html('<option value="">Select State</option>');
                $.each(res.data, function (key, value) { 
                    $('#selectstate').append('<option value="' + value.id + '" {{ old("state_id") == '+value.id+' ? "selected" : "" }} >  ' + value.state_name + '</option>');
                });  
            }); 
        }  
    });
</script>

how to improve my code to able get selected state. please help



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source