problems to upload data to a multiple select using multiselect bootstrap from ajax

0

Hi, I need to upload data to a multiple select with ajax using the jquery bootstrap-multiselect plugins: link with the method .multiselect ('dataprovider', data). the format of the varible data is an array of objects. What I have done so far is the following:

  $(document).ready(function () {
    $("#idpuntosAtencion").multiselect();

    function ajax(url, data, id, event) {
        setTimeout(function() {
            $.ajax({
                url: url,
                type: "POST",
                data: data,
                success: function (respuesta) {
                    event.preventDefault();
                  $(id).multiselect('dataprovider', respuesta);
                }
            });
        }, 900) 
    }
    $('#ciudadId').on('change',function(event){
          var data = {'ciudadId':$('#ciudadId').val()};
          ajax('Funtions/bloquerTurnoAll.php',data,'#idpuntosAtencion',event);
    });
    $('#idpuntosAtencion').on('change',function(event){
          var data = {'idpuntosAtencion':$('#idpuntosAtencion').val()};
          ajax('Funtions/bloquerTurnoAll.php',data,'#consultorioId',event);
    });

  });

bloquerTurnoAll.php

    if(isset($_POST['ciudadId']))
    {
        $query_puntoatencion = "SELECT puntosAtencion.idpuntosAtencion, puntosAtencion.nombre FROM puntosAtencion WHERE puntosAtencion.estado<>'I' AND puntosAtencion.ciudadId=$_POST[ciudadId]";
        $puntoatencion = mysqli_query($callcenter,$query_puntoatencion) or die(mysqli_error($callcenter));
        $row_puntoatencion = mysqli_fetch_assoc($puntoatencion);
        $totalRows_puntoatencion = mysqli_num_rows($puntoatencion);
        $option='';
        if ($totalRows_puntoatencion>0) {
            $option='[';
            do
            {
                $option.="{label: '".$row_puntoatencion['nombre']."', title: '".$row_puntoatencion['nombre']."', value: '".$row_puntoatencion['idpuntosAtencion']."'},";
            }
            while($row_puntoatencion = mysqli_fetch_assoc($puntoatencion));
            $option.=']';
        }else{
            echo '<option value="">Sin informacion para mostrar</option>';
        }
        echo $option;
    }

error in the console: TypeError: invalid 'in' operand a

in the php code I try to assemble the format of the data variable of the plugins. They could help me with what happens in this.

    
asked by Maikol Boscan 05.03.2017 в 01:06
source

2 answers

1

In the PHP code you are missing the single quotes when you select the cityId of the post.

    
answered by 05.03.2017 в 01:39
0

I can not comment, but have you tried to pass data as a string (JSON) and after that, convert that JSON into an object in your php with json_decode ?.

    
answered by 06.03.2017 в 17:21