pull information via php ajax [closed]

0

Good afternoon, I'm studying ajax and I'm trying to make an input pass to a file via post, but nothing happens .. I'm tracking via chrome firebug and I always see the type: 'post' is in error.

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><script>functionajax(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>
    
asked by anonymous 10.08.2016 / 20:41

1 answer

2

You have several small errors in your code, try this modified version:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script><form><label>Entrecomseunome:</label><inputtype="text" name="nome"><br>
<input type="button" name="Enviar" value="Enviar">
</form>

<div class="resultado">
Olá, <span class="nome"></span>
</div>

<script>
function ajax(nome){
    var nome = ;
    var 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(){
      ajax( $("input[name=nome]").val() );
    });
});
</script>
    
10.08.2016 / 21:27