AJAX DOES NOT SEND THE DATA TO PHP

0

The idea of the code is to prevent the page from reloading when sending a form, I read that the best option is with Ajax, but when doing it with ajax, it does not send me the data I need to the php I am using.

$(document).ready(function(){
    $('#button').click(function() {
    
        var cuenta = $("#cuenta").val();

        $.ajax({
            data: {"cuenta" : cuenta},
            url: "index.php",
            type: "post"
        });
        
        $("#parrafo").append(cuenta, ' ');
    
    });
});
<?php
$cuenta = isset($_POST['cuenta']) ? $_POST['cuenta'] : NULL;

var_dump($cuenta);

?>

<form action="" method="" onsubmit="return false">
     <div class="input-group mb-3">
          <input type="text" class="form-control" placeholder="Numero de Cuenta" name="cuenta" id="cuenta">
          <div class="input-group-append">
               <button class="btn btn-danger" type="button" id="button" name="button">Enviar</button>
          </div>
     </div>
     
     <p id="parrafo"></p>
</form>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    
asked by Víctor Álvarez 21.12.2018 в 16:14
source

0 answers