Advertisement
fahmihilmansyah

cobalah

Feb 24th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2. $asa = $_POST['coba'];
  3.  
  4. for($i=0; $i<= count($asa); $i++):
  5.     $isibaru = array('cobalah' => $asa[$i]);
  6. endfor;
  7. json_encode($isibaru);
  8.  ?>
  9.  
  10. =============================
  11. HTML
  12. =============================
  13.  
  14. <!DOCTYPE html>
  15. <html>
  16. <head>
  17.     <meta charset="utf-8">
  18.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  19.     <title></title>
  20.     <link rel="stylesheet" href="">
  21.     <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  22. </head>
  23. <body>
  24.     <form >
  25.         <input type="text" name="coba[]" value="" placeholder="">
  26.         <input type="text" name="coba[]" value="" placeholder="">
  27.         <input type="text" name="coba[]" value="" placeholder="">
  28.         <input type="text" name="coba[]" value="" placeholder="">
  29.         <input type="text" name="coba[]" value="" placeholder="">
  30.         <input type="submit" name="" value="">
  31.     </form>
  32.     <script type="text/javascript">
  33.         $( "form" ).submit(function( event ) {
  34.           console.log( $( this ).serializeArray() );
  35.           $.ajax({
  36.               type: "POST",
  37.               url: "http://localhost/coba/cobasubmit.php",
  38.               data: $( this ).serializeArray(),
  39.               success: function(data){
  40.                 console.log(data.cobalah);
  41.               },
  42.               dataType: "JSON"
  43.             });
  44.           event.preventDefault();
  45.         });
  46.     </script>
  47. </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement