I am new with jQuery. Currently I am trying to integrate jQuery with PHP and MySQL (using XAMPP) and the code is:
- <?php
- include "latihan36_1.php";
- $q = "select * from mhs";
- $ex = mysql_query($q);
- echo "<a href='#' id='tambah-mhs'>Tambah MHS</a>";
- echo "<table border=1>";
- echo "<tr>
- <th>NPM</th><th>Nama</th><th>Alamat</th>
- <th>No Telp</th><th>Action</th></tr>";
- while($r = mysql_fetch_array($ex)){
- echo "<tr><td>".$r['npm']."</td>";
- echo "<td>".$r['nama']."</td>";
- echo "<td>".$r['alamat']."</td>";
- echo "<td>".$r['no_telp']."</td>";
- echo "<td><a href='#' id='ubah-mhs' x=' ".$r['npm']."'>Ubah</a> ";
- echo "<a href='#' id='hapus-mhs' x=' ".$r['npm']."'>Hapus</a>";
- echo "</td></tr>";
- }
- echo "</table>";
- ?>
- <script type="text/javascript" src="jquery-1.12.3.js">
- $(document).ready(function(){
- $("#tambah-mhs").click(function(){
- $.get("latihan45.php",function(respon){
- $("#div-hasil").html(respon);
- });
- });
-
- $("#ubah-mhs").click(function(){
- var x = $(this).attr("x");
- $.get("latihan46.php", {n: x} function(respon){
- $("#div-hasil").html(respon);
- });
- });
-
- $("#hapus-mhs").click(function(){
- var x = $(this).attr("x");
- if(confirm("Anda yakin ingin menghapus data ini ?")) {
- $.get("latihan47.php", {n: x} function(respon){
- location.href = "latihan44.php";
- });
- };
- });
- });
- </script>
- <div id="div-hasil"></div>
My problem now is the page successfully connect to DB but when I click "Tambah MHS" (see no. 7) the page don't redirect to another page. it should be redirect to "latihan45.php" page (as stated in no. 27). Is there something wrong with my code?