I can do the data insertion but I have no idea how to do data selection on a HTML
using $.get
JSON
.
php code
public function Inserir($tabela,$sql){
ksort($sql);
$Campos_nome= implode('', '', array_keys($sql));
$Campos_valor= ':'. implode(', :', array_keys($sql));
$novo=$this->prepare("INSERT INTO $tabela ( '$Campos_nome') VALUES ( $Campos_valor)");
foreach ($sql as $key => $valor) {
$novo->bindValue(":$key", $valor);
}
$novo->execute();
if($novo->rowCount()>0){
$novo->setFetchMode(PDO::FETCH_ASSOC);
$valor=$novo->fetchAll();
print json_encode($valor,JSON_PRETTY_PRINT);
}
}//fim
Then I do the serialization of my Form
sending the data via POST to my php
file.
Here is the code:
$("#novo").submit(function(){
var url = $(this).attr('action');
var data = $(this).serialize();
$.post(url,data,function(data){
$('#result').append('<div>'+o.nome+'</div>');
console.log(o.nome);
});
return false;
});
How do I return values in tabela
or <li>
using method $.get
?
Note: I tried to do this using append
but it does not work correctly:
function listar(){
$.get(url,function(data){
$('#div').append('<div>'+data.nome+'</div>');
$('#div').append('<div>'+data.email+'</div>');
)};
}