Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
- <title>Ajax</title>
- <meta name="description" content="">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <body>
- <div id="divRetornoDoEchoJsonEncode"></div>
- <form method="POST" style="" action="recebe_form.php" class="ajaxForm">
- <input type="text" name="numero" />
- <button>Enviar</button>
- </form>
- <script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
- <script>
- let BASE = 'http://localhost/ajuda_grupo/wellingthon/';
- </script>
- <script>
- $(function() {
- $('.ajaxForm').submit(function(e) {
- e.preventDefault();
- let form = $(this);
- let action = form.attr('action');
- let dados = new FormData($(this)[0]);
- $.ajax({
- url: BASE + action,
- data: dados,
- type: 'POST',
- dataType: 'json',
- processData: false,
- contentType: false,
- success:function(json){
- $('#divRetornoDoEchoJsonEncode').html(json);
- }
- });
- });
- });
- </script>
- </body>
- </html>
- arquivo recebe_form.php que receberá os dados enviados do formulario via ajax,
- <?php
- $numero = filter_input(INPUT_POST,'numero',FILTER_DEFAULT);
- echo json_encode($numero);
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement