HTML + Ajax form with Jquery and PHP

Asked

Viewed 143 times

1

I have a form that has a native HTML5 date field and I need that in the Onchange event of that date field or change the date value it will call a Php page that will load my page.

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.

1 answer

0


Here is 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);
    }
  });
});

The ajax is called in the event change and send to PHP a GET with minhadataatual. In PHP you can do:

$data = $_GET['minhadataatual'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.