0
In the index.php
has 1 field input
that sends a value per ajax
, which must 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');
In the ajax request try the following:
data: {cdb: cdb},
. in cdb.php doesecho 'YOO ' .$_POST['cdb'];die();
to see if it returns this as a response– Miguel
@Miguel just put
data: {cdb: cdb}
and it worked ! Could you please publish the answer and explain why you have to do it this way ? Thank you very much !– rbz
I can’t right now, I’m in the car, but I believe some colleague might be able to do this favor
– Miguel
This request leads to a certain php controller?
– Gabriel.H
@Miguel tranquil ! They already answered ! But thank you for your attention !
– rbz
Gabriel, no controller, just a basic script ! But thank you !
– rbz