delucaspinto

[AJAX] FORM SERIALIZE

Jun 4th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Jquery Ajax Javascript
  2. $("#btn_salvar").click(function(e){
  3. e.preventDefault();
  4. var serializeDados = $('#form_cadastra_lancamento').serialize();
  5. $.ajax({
  6.     type: "POST",
  7.     url: "/cadastra-lancamento",
  8.     data: serializeDados,
  9.     success: function( response ) {
  10.         alert(response);
  11.         alert('ok');
  12.     }
  13. })
  14. })
  15.  
  16. //php
  17. $produto = new Produto;
  18. $produto->name = $_POST['name'];
  19. $produto->category = $_POST['category'];
  20. $produto->value = $_POST['value'];
  21. $produto->description = $_POST['description'];
  22. $produto->save();
Advertisement
Add Comment
Please, Sign In to add comment