Published June 30, 2019 by RIT

HOW TO INSERT AJAX IN PHP

Assalamualaikum warohmatullohi wabarokatuh,
Wa alaikum salama warohmatullohi wabarokatuh,

cara input data dengan ajax
how to insert ajax in php

1 - buatlah file index.php
2 - buat file lagi dengan nama create_proses.php
3 - copy script dibawah ini sesuaikan dengan file index.php dan create_proses.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php 
$koneksi = mysqli_connect('localhost','root','','test');
?>
<script type="text/javascript" src="jquery.js"></script>
 
<!-- form untuk menambah data -->
<form method='post' class='form-input'>
    <input type='text' name='nama' >
    <input type='submit' class='save' value='submit'>
</form>
 
<!-- script menampilkkan data -->
<?php 
$q  = 'SELECT * FROM tb_siswa';
$q2 = mysqli_query($koneksi, $q);
 
?>
 
<table border="1" >
    <tr bgcolor="yellow" align="center">
        <td>NAME</td>
    </tr>
 
<?php while ( $row = mysqli_fetch_array($q2)) { ?>
    <tr>
        <td><?php echo $row['nama']; ?></td>
    </tr>
<?php } ?>
 
</table>
 
<!-- script jquery ajax input data -->
<script type="text/javascript">
  $(document).ready(function(){
      $(".save").click(function(id){
        
           var data = $('.form-input').serialize();
           var notif = alert('insert success ... !!!');
        
            $.ajax({
              type: 'POST',
              url: "create_proses.php",
              cache: false,
              data: data,
              success: function(notif){
                  location.reload();
                }
            });
          });
      });
</script>

1
2
3
4
5
6
7
<?php 
require_once 'index.php';
$nama   = $_POST['nama'];
$query  = "INSERT INTO tb_siswa (nama) VALUES ('$nama')";
$query2 = mysqli_query($koneksi,$query);
return $query2;
 ?>



berikut adalah hasil dari script ajax php.


Terima Kasih
Thank's

TAG TAGS :
how to insert ajax php | cara input data dengan ajax | cara insert data dengan ajax php | cara menampilkan data tanpa refresh | input data ke database tanpa refresh | script sederhana crud ajax php | script simple crud ajax php | script crud php | script crud php ajax | download script ajax | scripts ajax jquery | script ajax jquery | how to insert ajax in php | how to insert ajax in html | script insert php ajax | how to insert ajax loader | how to insert data using ajax in php | how to insert using ajax in php | how to add ajax in php | PHP Ajax Scripts | Free PHP Ajax Scripts | PHP Ajax Downloads |


BACA JUGA :

Comments: