Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program index.php
- <!doctype html>
- <html lang="en">
- <head>
- <title>Menghapus Data Tanpa Merefresh Halaman dengan Ajax</title>
- <meta content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" name="viewport"/>
- <meta content="Aguzrybudy" name="author"/>
- <link href="css/bootstrap.css" rel="stylesheet">
- <script src="js/jquery.min.js"></script>
- <script src="js/bootstrap.min.js"></script>
- </head>
- <body>
- <div class="container">
- <h2>
- Menghapus Data Tanpa Merefresh Halaman dengan Ajax</h2>
- <p>
- <a href="#" class="btn btn-success" data-target="#ModelAdd" data-toggle="model">Add Data</a></p>
- <table id="mytable" class="table table-bordered"><thead> <th>id</th> <th>Name</th> <th>Alamat</th> <th>Jabatan</th> </thead> <?php
- include "koneksi.php";
- $no = 0;
- $model=mysqli_query($kon,"SELECT * FROM model");
- while($r=mysqli_fetch_array($model)){
- $no++;
- ?>
- <tr> <td><?php echo $no; ?></td> <td><?php echo $r['model_nama']; ?></td> <td><?php echo $r['description']; ?></td> <td>
- <a href="#" class='open_model' id='<?php echo $r['model_id']; ?>'>Edit</a>
- <a href="#" onclick="confirm_modal('proses_delete.php?&model_id=<?php echo $r['model_id']; ?>');">Delete</a>
- </td> </tr>
- <?php } ?> </table>
- </div>
- <script type="text/javascript">
- $(document).ready(function () {
- $(".open_modal").click(function(e) {
- var m = $(this).attr("id");
- $.ajax({
- url: "modal_edit.php",
- type: "GET",
- data : {model_id: m,},
- success: function (ajaxData){
- $("#ModalEdit").html(ajaxData);
- $("#ModalEdit").modal('show',{backdrop: 'true'});
- }
- });
- });
- });
- </script>
- <script type="text/javascript">
- function confirm_modal(delete_url)
- {
- $('#modal_delete').modal('show', {backdrop: 'static'});
- document.getElementById('delete_link').setAttribute('href' , delete_url);
- }
- </script>
- </body>
- </html>
- koneksi.php
- <?php
- error_reporting(E_ALL ^ E_DEPRECATED);
- $host = "localhost";
- $user = "root";
- $pass = "";
- $dbName = "teknologiweb2";
- $kon = mysqli_connect($host, $user, $pass);
- if (!$kon)
- die("Gagal Koneksi...");
- $hasil = mysqli_select_db($kon, $dbName);
- if (!$hasil) {
- $hasil = mysqli_query($kon, "CREATE DATABASE $dbName");
- if (!$hasil)
- die("Gagal Buat Database");
- else
- $hasil = mysqli_select_db($kon, $dbName);
- if (!$hasil) die ("Gagal Konek Database");
- }
- $sqlTabelModel = "create table if not exists model (
- model_id int(11) auto_increment not null primary key,
- model_nama varchar(10) not null,
- description text,
- date timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
- KEY(model_id))" ;
- mysqli_query ($kon, $sqlTabelModel) or die("Gagal Buat Tabel Model");
- ?>
- delete.php
- <?php
- include "koneksi.php";
- $model_id=$_GET['model_id'];
- $model=mysqli_query($kon,"Delete FROM model WHERE model_id='$model_id'");
- header('location:index.php');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement