-1
I want to create a dynamic form but I get the following error:
javprogram.js:377 Uncaught Typeerror: "#retorno3". html is not a Function At Object.Success (javprogram.js:377) at fire (jquery-Latest.js:3119) At object.fireWith [as resolveWith] (jquery-Latest.js:3231) done (jquery-Latest.js:9275) At Xmlhttprequest.callback (jquery-Latest.js:9685)
Code to create the form: HTML:
<form action="#!" id="retper">
</form>
JS:
$(document).on('click', '.view_perfil', function(){
var perf = $(this).attr("id_perfil");
$.ajax({
url:"perfil.php",
method:"POST",
cache: false,
data:{perf:perf},
dataType:"json",
success:function(data){
var linha = ``;
for (var i = 0; i < data.length; i++) {
Nome = data[i][0];
Email = data[i][1];
Acesso = data[i][2];
Foto = data[i][3];
linha += `<div class="form-group col-md-6">
<input type="text" class="form-control" value="${Nome}">
<span class="form-highlight"></span>
<span class="form-bar"></span>
<label for="Utilizador">Nome</label>
</div>
<div class="form-group col-md-6">
<input type="text" class="form-control" value="${Email}">
<span class="form-highlight"></span>
<span class="form-bar"></span>
<label for="Email1">Email</label>
</div>
<div class="form-group col-md-6">
<input type="text" class="form-control" value="${Acesso}">
<span class="form-highlight"></span>
<span class="form-bar"></span>
<label for="Acesso">Acesso</label>
</div>
<div class="form-group col-md-6">
<label class="filelabel">
<i class="fa fa-paperclip">
</i>
<span class="title">
Add Foto
</span>
<img src="./images/${Foto}" alt="">
</label>
</div>`;
}
("#retper").html(linha);
}
});
});
php:
$perf = $_POST["perf"];
$stmt = $conn->prepare("SELECT dados.Utilizadores.Nome, Email, dados.Niveis_Acessos .Nome AS Acesso, Foto
FROM dados.Utilizadores LEFT OUTER JOIN dados.Niveis_Acessos
ON dados.Niveis_Acessos.Id = dados.Utilizadores.Niveis_acesso_id WHERE dados.Utilizadores.Id = :perf");
$stmt->bindValue(':perf', $perf, PDO::PARAM_INT);
$stmt->execute();
$json = [];
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
$json[]= [(string)$Nome, (string)$Email, (string)$Acesso, (string)$Foto];
}
echo json_encode($json);
I already checked and the php script returns the data correctly. The problem is when building the HTML
.
$("#retper"). html(line); Missed the $
– user60252