How to send two variables ajax, json

0

Hello I would like to send by post with the following code, two variables I can only send one, any suggestions? Thanks

<script type="text/javascript">
$(document).ready(function() {
    $("#au").change(function() {
        $.ajax({
            url: "post.php",
            type: "POST",
            data: "aula=" + $("#au").val(),
            success: function(opciones) {
                $("#hst").html(opciones);
            }
        })
    });
});
</script>
    
asked by Alexander Quiroz 10.01.2017 в 18:44
source

1 answer

3

To send several variables you could do it like this:

$.ajax({
      type: "POST",
      dataType: 'json',
      data: {'aula': $("#au").val(), 
             'variable2': valor}, //valor debes reemplazar con algo valido, de esta manera puedes enviar el numero de variables que necesites.
      url: "post.php",
      success : function(data) {

          console.log(data);

      }
  });
    
answered by 10.01.2017 / 18:48
source