1
I can do data entry but 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 mine Form
send the data via POST to my archive php
.
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 the values in a tabela
or <li>
using method $.get
?
Note: I tried to do this using append
but it doesn’t work properly:
function listar(){
$.get(url,function(data){
$('#div').append('<div>'+data.nome+'</div>');
$('#div').append('<div>'+data.email+'</div>');
)};
}
I didn’t understand your question, what do you mean "selection of data in an html"? It became somewhat vague... In case you want to filter the information coming in json?
– Marcelo Aymone
You can put your HTML to make the question clearer?
– Sergio
@Sergio he needs to post PHP too, if he doesn’t have a return json header, it won’t work.
– Filipe Moraes
@Sam did an edit because as now I know to return an array so the code has to be that!!!
– user6026