简体   繁体   中英

As a two-dimensional array receive from an ajax

Through an Ajax, I'm doing a query that returns me an array with two positions to create a pick list created with javascript. In the first value that has the value and the second has the name (The name and value are the same).

This is the answer of my ajax:

var valores = new Array();
var nombres = new Array();

for (var i = 0; i < respuesta.length ; i++)
 {
  valores[i] = respuesta[i]["COLUMN_NAME"];
  nombres[i] = respuesta[i]["COLUMN_NAME"];
 }
 documentopropiedades.opciones[3] = [valores,nombres];

Being documento.propiedades [3] the place where the list.

When I go to create the form everything goes normal full list like this:

var valorCampo =  Array();
var nombreCampo =  Array();
campotabla = [valorCampo,nombreCampo];

And it brings me the data but when I go to edit me not load form the data I have already recorded in the database on this select, tried running again ajax within the document.ready but I can not get me to load data the select

You cannot recieve arrays by a ajax call. So you just encode it in php and decode in javascript!

In PHP:

echo json_encode($multi_dimensonal_array);

In your ajax request:

multi_dimensonal_array = JSON.parse(multi_dimensonal_array);

$.ajax({
    url: 'get_array.php',
    type: 'POST',
    data: {data: send}
}).done(function(multi_dimensonal_array){
    multi_dimensonal_array = JSON.parse(multi_dimensonal_array);
    console.log(multi_dimensonal_array[0]);
    console.log(multi_dimensonal_array[1]);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM