L.Freitas
L.Freitas

Reputation: 11

Error: Cannot read property 'each' of undefined

I have a JavaScript code that returns values of a PHP and assembles an HTML table. Is giving the error can not read property of each undefined. I've looked several times without success. They could give me a hand? The following 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, guys.

Upvotes: 0

Views: 1530

Answers (1)

rzelek
rzelek

Reputation: 4023

Looks like jQuery is not available using $, try jQuery instead.

Change this line:

$.each(resposta, function(){ 

to this:

jQuery.each(resposta, function(){

Upvotes: 2

Related Questions