How do I return 2 array to the Ajax success? [closed]

-1

Controller ....

    function getCompetencias(){
        $query['competencia'] = $this->studentCompetencias_model->getCompetencias();
        $encon = json_encode($query);

        $student = $_POST['alumno'];
        $teacher = $_POST['clase'];
        $queryA['atributo'] = $this->studentCompetencias_model->getAtributos($student,$teacher);
        $enconA = json_encode($queryA);

        echo $encon,$enconA;
}

JQuery (AJAX)

$.ajax
          ({
            type: 'POST',
            data: {alumno: id, clase: idAsgin},
            url: '<?= base_url()?>EvaluarCompetencias/getCompetencias',
            success: function(data){
              var obj = JSON.parse(data);
              alert(obj);
            },error: function(){
              alert("algo salio mal");
            }
          });
    
asked by El Tío 17.12.2018 в 05:48
source

2 answers

1

With an associative array

echo json_encode( array( 'vocales'=> ['a','e','i'], 'numeros'=>[1,2,3]) );

And in your success function you will have this structure that you can work easily

{"vocales":["a","e","i"],"numeros":[1,2,3]}
    
answered by 17.12.2018 / 06:18
source
0

When using associative array, and to be able to extract the data, the positions of the array must be added first, then the name of the array after the position of the data and at the end the data.

obj [0] ['competition'] [i]. final data;

    
answered by 17.12.2018 в 07:06