Select cities and states on the site [closed]

2

I'm setting up a site , and on the home page I've created a select for states and cities, the problem is that the homepage site is crashing very.

Does anyone know how I can do this select without crashing the site ? Or maybe do it another way?

The site link is link

<?php 

ItemForm::region_select(osc_get_regions(osc_user_region()), osc_user()); ?> </div>
</div>
<div class="col-md-3">
    <div class="cell selector">
        <!--------------City-------------------->
        <?php ItemForm::city_select(osc_get_cities(osc_user_region()), osc_user()); ?>
        <!--------------City End-------------------->
    </div>
</div>
<div class="col-md-2">
    <div class="cell reset-padding">
        <button class="btn btn-success btn_search">
            <?php _e( "Search", 'osclasswizards');?> </button>
    </div>
</div>
</div>
</div>
<div id="message-seach"></div>
</div>
</div>
</form>
<script type="text/javascript">
    $(document).ready(function() {
        $("#regionId").on("change", function() {
            var pk_c_code = $(this).val(); <? php
            if ($path == "admin") { ?>
                var url = '<?php echo osc_admin_base_url(true)."?page=ajax&action=cities&regionId="; ?>'
                pk_c_code; <? php
            } else { ?>
                var url = '<?php echo osc_base_url(true)."?page=ajax&action=cities&regionId="; ?>'
                pk_c_code; <? php
            }; ?>
            var result = '';
            if (pk_c_code != '') {
                $("#cityId").attr('disabled', false);
                $.ajax({
                    type: "POST",
                    url: url,
                    dataType: 'json',
                    success: function(data) {
                        var length = data.length;
                        if (length > 0) {
                            result = '<option selected value=""><?php _e("Select a city..."); ?></option>';
                            for (key in data) {
                                result = '<option value="'
                                data[key].pk_i_id '">'
                                data[key].s_name '</option>';
                            }
                            $("#city").before('<select name="cityId" id="cityId" ></select>');
                            $("#city").remove();
                        } else {
                            result = '<option value=""><?php _e('
                            No results ') ?></option>';
                            $("#cityId").before('<input type="text" name="city" id="city" />');
                            $("#cityId").remove();
                        }
                        $("#cityId").html(result);
                    }
                });
            } else {
                $("#cityId").attr('disabled', true);
            }
        });
        if ($("#regionId").attr('value') == "") {
            $("#cityId").attr('disabled', true);
        }
    });
</script>
    
asked by anonymous 22.06.2015 / 18:53

1 answer

0

The immediate problem seems to be neither the query nor jQuery: your homepage has more than one megabyte ! The first business order is you push the query that pulls the list of cities to another page and load via AJAX (the second business order is, on the page that pulls the list of cities, filter through the state that the user chose).

I did not see the code you wrote, but apparently you are pulling the data via PHP (which generates the brick I mentioned above) and then does the AJAX (to pull the data that has already come in the first run ); gives a Ctrl + S and looks at the resulting file size so you can see that the list of cities is coming from the original page load.

    
22.06.2015 / 19:47