javascript - 错误: Cannot read property 'each' of undefined

标签 javascript php

我有一个 JavaScript 代码,它返回 PHP 的值并组装一个 HTML 表。给出错误无法读取每个未定义的属性。我看了好几遍都没有成功。他们可以帮我吗? 代码如下:

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;

?>

谢谢大家。

最佳答案

看起来 jQuery 无法使用 $,请尝试使用 jQuery

更改此行:

$.each(resposta, function(){ 

对此:

jQuery.each(resposta, function(){

关于javascript - 错误: Cannot read property 'each' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36342091/

相关文章:

javascript - Redux、规范化实体和 lodash 合并

php - 如果在 WooCommerce Checkout 中选中自定义复选框,则删除运费

php - 尝试使用 PHP 和 MySQL 中的逻辑将某些内容分配给 "rule"

PHP If Else with isset : else part does not work

javascript - 增加 z-index 和降低不透明度的幻灯片

javascript - 如何从 JavaScript 中完全禁用键盘快捷键

javascript - 根据条件渲染依赖于 useState 的功能组件

javascript日期验证检查

php - 如何在 php 中突出显示选定的选项卡?

php - SQL求职功能问题