No index.php
has 1 field input
that sends a value by ajax
, which should be read by cdb.php
.
index.php:
<script type="text/javascript">
$(document).ready(function(){
$("#formulario").on("submit", function(e){
e.preventDefault();
var cdb = $("#cdb").val();
$.ajax({
url: "cdb.php",
method: "POST",
dataType: "html",
data: cdb
}).done(function(data){
$("#cdb").val("");
$("#cdb").focus();
listar();
}).fail(function(data){
alert("Erro");
});
});
});
</script>
...
<form id="formulario" method="POST" action="" accept-charset="utf-8">
<div>
<?php echo rand(1, 100) ?>
<input id="cdb" type="text" name="cdb" class="validate" required autofocus onfocus="this.value='';">
<button type="submit">GRAVAR</button>
</div>
</form>
cdb.php
$cdb = filter_input(INPUT_POST,'cdb');