Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $asa = $_POST['coba'];
- for($i=0; $i<= count($asa); $i++):
- $isibaru = array('cobalah' => $asa[$i]);
- endfor;
- json_encode($isibaru);
- ?>
- =============================
- HTML
- =============================
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <title></title>
- <link rel="stylesheet" href="">
- <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
- </head>
- <body>
- <form >
- <input type="text" name="coba[]" value="" placeholder="">
- <input type="text" name="coba[]" value="" placeholder="">
- <input type="text" name="coba[]" value="" placeholder="">
- <input type="text" name="coba[]" value="" placeholder="">
- <input type="text" name="coba[]" value="" placeholder="">
- <input type="submit" name="" value="">
- </form>
- <script type="text/javascript">
- $( "form" ).submit(function( event ) {
- console.log( $( this ).serializeArray() );
- $.ajax({
- type: "POST",
- url: "http://localhost/coba/cobasubmit.php",
- data: $( this ).serializeArray(),
- success: function(data){
- console.log(data.cobalah);
- },
- dataType: "JSON"
- });
- event.preventDefault();
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement