0
good afternoon, I am studying ajax and I am trying to make an input pass to a file via post, but nothing happens.. I am following via Chrome firebug and I see that always the type: 'post' is in error.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
function ajax(nome){
info = {"nNome" : nome};
$.ajax({
type: 'post';
url: "arquivo.php";
data: info,
}).done(function(data) {
data = $.parseJSON(data);
$(".resultado span.nome").text(data.nNome);
});
}
$(document).ready(function(){
$("input[name=Enviar]").click(function(){
var nome = $("input[name=nome]").val();
});
});
</script>
<form>
<label>Entre com seu nome:</label>
<input type="text" name="nome"><br>
<input type="button" name="Enviar" value="Enviar">
</form>
<div class="resultado">
Olá, <span class="nome"></span>
</div>
The mistake are the
;
inside object, you should be using commas.– bfavaretto
OK, I made the changes and really that was the mistake, but I still can’t display the result...
– Vinicius Nakamura
Please show what your.php file does.
– Kayo Bruno
<?php

echo json_encode($_POST);

?>
– Vinicius Nakamura
data.nNome
should also not bedata.nome
? Anyway, it will be hard to see the value change if what you return in PHP is the same as what you just sent. The.text()
will trade six for half a dozen.– bfavaretto
then as to the date.nName it is pulling via Indice.. which comes through the
info = {"nNome" : nome };
, it should appear in the div below... it’s just a test to learn and apply in other files...– Vinicius Nakamura