Utilizar datos JSON de AJAX en otras funciones
Publicado por giuli (19 intervenciones) el 03/06/2018 16:36:19
Este codigo me funciona perfecto:
Entonces hago:
y aparecen todos los registros..
Pero quiero filtrar los datos, pero utilizando console.log el array JSON no llega, aparece undefined :
que puedo hacer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function listar(){
tipofiltro="todos";
$.ajax({
type: "POST",
url: "../gestionweb/includes/php/filtroP.php",
data: { "tf": tipofiltro},
dataType: "json",
error: function(){
alert("error petición ajax");
},
success: function(data){
for (var i = 0; i < data.length; i++) {
var newRow =
"<tr>" +
"<td>" + data[i].idproducto + "</td>" +
"<td>" + data[i].nombre + "</td>" +
"<td>" + data[i].marca + "</td>" +
"<td>" + data[i].categoria + "</td>" +
"<td>" + data[i].precio + "</td>" +
"</tr>";
$(newRow).appendTo("#resultado");
}
};
});
}
Entonces hago:
1
2
3
4
$(document).ready(function() {
listar();
});
y aparecen todos los registros..
Pero quiero filtrar los datos, pero utilizando console.log el array JSON no llega, aparece undefined :
1
2
3
4
5
6
7
8
9
10
11
$("#nombre").keyup(function() {
var nombreBusqueda=$("#nombre").val();
alert(nombreBusqueda);
filtrado=data.filter(function (v){
return v.nombre ^= nombreBusqueda;
});
console.log(filtrado.nombre)
});
Valora esta pregunta


0