1
I have a Javascript code that returns values from a PHP and mounts an HTML table. You are giving the error Cannot read Property 'each' of Undefined. I looked several times without success. Could you give me a hand? Follow the code:
Javascript:
function getListaItems(idprojeto) {
//alert(idprojeto);
jQuery.ajax({
type: "POST",
url: "get-lista-items.php?idprojeto=" + idprojeto,
//data: dataEvento,
dataType: 'json',
success: function(resposta) {
var str_html = '';
$.each(resposta, function(){
str_html = str_html + '<tr class="gradeA" id="' + this.id + '">' +
'<td class="center"><input type="checkbox" id="item[]" name="item[]" onchange="changeColor(' + this.id + ')" value="' + this.id + '" /></td>' +
'<td class="center">' + this.descricao + '</td>' +
'<td class="center">' + this.descCategoria + '</td>' +
'<td class="center">' + this.descCaracteristica + '</td>' +
'<td class="center">' + this.descMedida + '</td>' +
'<td class="center"><input type="text" id="qtd' + this.id + '" style="width:80px"/></td>' +
'</tr>';
});
document.getElementById("resultJs").innerHTML = str_html;
}
});
}
PHP:
<?php
session_start();
require_once("ProjectIncludes.php");
$service = new ProjetoxItensService();
$consulta = $service->getAll($_GET['idprojeto']);
$retorno = json_encode($consulta);
echo $retorno;
?>
Thanks in advance.
Have you checked if your json is not coming empty in the ajax request?
– Jhonny Mesquita
Yeah. I already checked. It’s straight.
– L.Freitas
Apparently $ is undefined, somewhere on the page the $ is set as Undefined or is made a delete above the same?
– Gabriel Katakura
I found the problem. I replaced it $ that comes in front of the each for jQuery.
– L.Freitas