Get field on front with ajax

Discussion in 'Subrion CMS Plugins Discussion' started by coquendo, Nov 13, 2018.

  1. coquendo

    coquendo New Member

    Hello colleagues developers,
    I try to do a change of values with ajax but not work as I hope.
    When I debug the code, in PHP it work ok, but in the response in javascript is empty. I use de same code in a admin page and it work ok
    I've the following code:
    js==
    Code (Javascript):
    $(document).ready(function () {
        //chance cities
        $("#state").change(function() {
            $("#state option:selected").each(function() {
                state_id = $(this).val();
                intelli.post(intelli.config.ia_url + 'actions.json', {action: 'get-cities', state_id: state_id},
                function (response) {
                    $("#city").empty();
                    $("#city").append(new Option('-- select --', 0));
                    response.forEach(element => {
                        $("#city").append(new Option(element.city, element.id));
                    });
                });
            });
        });
    }
    PHP (/front/action.php) ==
    PHP:
    case 'get-cities':
                if (iaView::REQUEST_JSON == $iaView->getRequestType()) {
                    $state = $_POST['state_id'];
                    $cities = [];
                    if (!empty($state)) {
                        $cities = $iaDb->assoc('id, city', 'state='.$state, 'city');
                        $iaView->assign('cities', $cities);
                        return $cities;
                    }
                }
                break;
    Any idea.

Share This Page