I have the following script, which processes the form and updates the list # div by ajax:
<script type="text/javascript">
$(document).ready(function(){
$("#formulario").on("submit", function(e){
e.preventDefault();
var cdb = $("#cdb").val();
$.ajax({
url: "confere.php",
method: "POST",
dataType: "html",
data: {cdb: cdb}
}).done(function(data){
$("#cdb").val("");
$("#cdb").focus();
listar();
}).fail(function(data){
alert("Erro");
});
});
});
function listar() {
$.ajax({
url:"lista.php",
success: function (textStatus) {
$('#lista').html(textStatus);
}
});
}
</script>
What I would like was to treat the return of confere.php
, and not only validate with .done
and .fail
.
For example:
The return of confere.php
can be "X", "Y", "Z", and according to return, perform an action.
File: confere.php
<?php
$cdb = filter_input(INPUT_POST,'cdb');
$valor = $cdb/10;
gravar($valor);
function gravar($texto){
$arquivo = "temp.txt";
$fp = fopen($arquivo, "a+");
fwrite($fp, $texto . ";");
fclose($fp);
}
?>