Sending data with php / jquery to mysql

-2

HowcouldIsendtheindex.phpscreendatatomysql,usingjavascript/jquerytodothisfunctionthatisbeingshownintheimagebelow.

Mycodeisbelow:

Myindex

<div class="container"> <h1 class="restaurant-title">Peixaria</h1> <div id="menu-panel" class="col-sm-12 paddingselect"> <?php categoriaas(); ?> </div> <div id="menu-panel-2"></div> <div id="caja-panel"> <div class="well"> <!-- left --> <div id="theproducts" class="col-sm-5"></div> <!-- left --> <input type="text" id="theinputsum"> <!-- right --> <div id="thetotal" class="col-sm-7"> <h1 id="total"></h1> <button class="btn btn-lg btn-success btn-block"> <i class="fa fa-shopping-cart" aria-hidden="true"></i> Finalizar Pedido </button> </div> <!-- right --> </div> </div> </div> <!-- container --> <!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> <script src="js/jquery.min.js"></script> <!-- Include all compiled plugins (below), or include individual files as needed --> <script src="js/bootstrap.min.js"></script> <!-- Restaurant --> <script src="js/restaurant.js"></script>

My processfunction :

require_once 'resfunctions.php';

if (isset($_POST['categoria'])) {
    getproductos($_POST['categoria']);
}

And others that if I put in the question will get great. I'm grateful right away.

    
asked by anonymous 01.02.2017 / 19:04

1 answer

1

Since you're already using jQuery, use its Ajax function ( link ).

You call the PHP file that will insert into MySQL, give a return to the javascript and do the other javascript procedures.

An example of using the ajax function

$.ajax({
  method: "POST",
  url: "some.php",
  data: $("#iDdoForm").serialize()
})
  .done(function( retorno) {
    alert( "faça as ações necessárias de acordo com o retorno" );
  });
    
01.02.2017 / 19:14