I'm doing a test with ajax and php, however it's returning a value nothing to see
test2.html
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<script src="jquery-3.3.1.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>
Nome: <input type="text" name="nome">
<input type="button" value="Enviar" onclick="enviar(name.valueOf())">
<p id="abc"> </p>
</div>
<script>
function enviar(nome) {
$.ajax({
url: "teste2.php",
type: "POST",
data: "nome=" + nome,
dataType: "html"
}).done(function (resposta) {
console.log(resposta);
}).fail(function () {
console.log("Falha");
}).always(function () {
console.log("Ok");
});
}
</script>
</body>
</html>
test2.php
<?php
if($_POST){
$vlr = $_POST['nome'];
if($vlr == 'Leandro'){
return true;
} else {
return false;
}
}
This comes back:
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined variable: nome in C:\wamp64\www\php_pdo\projeto\teste2.php on line <i>6</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.4036</td><td bgcolor='#eeeeec' align='right'>403528</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp64\www\php_pdo\projeto\teste2.php' bgcolor='#eeeeec'>...\teste2.php<b>:</b>0</td></tr>
</table></font>
One more question, as per the result in the paragraph (below the input)? I have tried document.getElementyId("abc").innerHTML = resposta;
, but the error that document.getElementyId
is not a function.