我有一个 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/