Form HTML + Ajax with Jquery and PHP

1

I have a form that has a date field that is native to HTML5, and I need to call a Php page that will load my page in the OnChange event of that date field.

Example of my html code:

<form id="formulario" method="GET">
    <input type="date" name="minhadataatual"/>
</form>

How to configure Jquery and Ajax and how to receive the date in PHP. My only doubts are these.

    
asked by anonymous 19.08.2017 / 14:21

1 answer

0

Here's a suggestion:

$('input[name="minhadataatual"]').on('change', function(e) {
  $.ajax({
    url: '/url/para/ficheiro.php',
    method: 'GET', // ou POST
    data: {
      // os dados a enviar 
      minhadataatual: this.value
    }, 
    success: function(resposta) { // função corrida no sucesso do ajax
      alert(resposta);
    }
  });
});

Ajax is called in the change event and sends a GET with minhadataatual to PHP. In PHP you can do:

$data = $_GET['minhadataatual'];
    
19.08.2017 / 14:27