0
Good morning, you guys.
I’m starting with PHP, and I’m trying to do some practical tests.
I created an input text and when pressing the "ENTER" key is called an ajax doing post of this data and calls the file control.php, but in the browser log is not mentioning nor the "Success" message of .done
nor "Error" of .fail
, let alone the message of controle.php
.
Can you explain to me what is happening in these scripts?
tela.php
<script src="jquery-3.3.1.js"></script>
<script src="script.js"></script>
<form>
<div class="row">
Campo de Texto:
<input id="id_text" style="height: 25px; font-size:12px; width: 100px" type ="text">
</div>
</form>
script js.
$(document).ready(function(){
var texto = document.getElementById('id_text').value;
$('#id_text').bind("enterKey",function(e){
console.log("Pressionado ENTER "+ texto);
$.ajax({
type: 'POST',
url: "controle.php",
data: {
'texto': texto
}
}).done(function(data) {
console.log("Sucesso");
}).fail(function(data){
console.error("Ajax Error");
});
});
$('#id_text').keyup(function(e){
if(e.keyCode == 13){
$(this).trigger("enterKey");
}
});
});
php control.
<?php
$reqmethod = $_SERVER['REQUEST_METHOD'];
if($reqmethod == 'POST'){
$texto = filter_input(INPUT_POST, "texto");
echo "O texto é: " + $texto;
}else{
echo "Não é um POST";
}
?>
Dear, there is no need to create two answers, just edit the first.
– Jorge.M
Oops, thanks for the info, I hadn’t thought of it. I deleted the old message to avoid confusion. Thanks.
– Leandro Sena