3
I would like to convert this code into jquery.
To say. Instead of appearing in iframe, I would like it to be a single page normally, and the insertion is refreshless.
$.post("resultado.php", function(result){
$("#id").val(result.id);
$("#nome").val(result.nome);
$("#idade").val(result.idade);
}
);
I had thought about the $.get
/post(function(resposta))
,
only that the here returns only a single answer and not the complete result that I would like.
The result page.php:
<?
$mysqli = new mysqli("localhost", "usuario1", "senha1","banco1");
if($_GET[id]) {
$res_a = $mysqli->query("select id, nome, idade from usuarios where id='$_GET[id]'");
$res_b = $res_a->fetch_assoc();
$id = $res_b[id];
$nome = $res_b[nome];
$idade = $res_b[idade];
?>
<table>
<tr>
<td>ID</td><td><input value="<?=$id?>"></td></tr>
<td>NOME</td><td><input value="<?=$nome?>"></td></tr>
<td>IDADE</td><td><input value="<?=$idade?>"></td></tr>
</table>
<? exit; } ?>
<table width="100%">
<tr>
<td>
<table>
<?
$result = $mysqli->query("select id, nome from usuario");
while($row = $result->fetch_assoc()) {
?>
<tr>
<td><a href="?id=<?=$row[id]?>" target="frame"> <?=$row[id]?> </a></td>
<td><a href="?id=<?=$row[id]?>" target="frame"> <?=$row[nome]?> </a></td>
</tr>
<? } ?>
</table>
</td>
<td>
<iframe name="frame" />
</td>
</tr>
</table>
What gives
console.log(result);
? That page"resultado.php"
is the same as in the question? in which case I don’t see where you’re sending back to ajax/post the data you want.– Sergio
Pablo, Thanks for commenting. log(result), is the default return..
– Diego Fernandes
I don’t really know how to explain it. But what I would like is that,, instead of using this IFRAME, it gave me a return via jquery (which I still don’t quite understand JQUERY,, and it was recently that I learned this $.post/$.get function). Pablo,, look at an example of what I would like,, only without iframe >> . www.diegosti.Hol.es/temp.php . . , but,, I don’t know how to do exactly this, in jquery Jquery, takes the ID, and inserts the SQL into the next input..
– Diego Fernandes