Rafie Gilang Rafie Gilang - 1 month ago 5x
Javascript Question

Jquery post data show up in url

I want to make a dynamic html table using w3css, im using jquery $.post but it doesnt seem to work.Other script like this one is working find in my other html file.

in my adress bar this url show up after excuting the jquery.


<div class="w3-container w3-animate-bottom">
<div class="w3-center">
<h2>Buku Kontak Pegawai</h2>
<div class="w3-responsive w3-card-4">
<table id="table" class="w3-table w3-striped w3-bordered">
<tr class="w3-theme">
<th>No. Personel</th>
<th>Gate ID</th>
<th>No. HP</th>
<th>Edit Admin</th>
<tr w3-repeat="admin">
<td><button class="w3-btn w3-small w3-white w3-border w3-border-blue w3-round-xlarge" >edit</button></td>
<td><button class="w3-btn w3-small w3-white w3-border w3-border-red w3-round-xlarge" onclick="pilih(this)">X</button></td>


<button class="w3-btn w3-green" onclick="modalTambah()">Tambah Admin</button>
<button class="w3-btn w3-red">Delete Admin</button>

<!-- Modal that pops up when you click on "New Message" -->
<div id="tambah" class="w3-modal" style="z-index:4">
<div class="w3-modal-content w3-animate-zoom">
<div class="w3-container w3-padding w3-red">
<span onclick="document.getElementById('tambah').style.display='none'" class="w3-right w3-xxlarge w3-closebtn"><i class="fa fa-remove"></i></span>
<h2>Tambah Admin</h2>
<div class="w3-container">
<form class="w3-container">
<label>No. Personel</label>
<input name ="nopersonel" class="w3-input w3-border w3-hover-border-black" type="text">

<label>Gate ID</label>
<input name ="gateid" class="w3-input w3-border w3-hover-border-black" type="text">

<input name ="pass" class="w3-input w3-border w3-hover-border-black" type="password">

<label>Ulangi Password</label>
<input name ="ulpass" class="w3-input w3-border w3-hover-border-black" type="password">

<a class="w3-btn w3-red" onclick="document.getElementById('tambah').style.display='none'">Batal</a>
<button id="tambahbtn"class="w3-btn w3-right w3-green">Tambah</button >

admin.html script



if(respone == "abort"){
alert("Silahkan Login Terlebih Dahulu.");
window.location.href = 'home.html';


w3Http("table.php", function () {
if (this.readyState == 4 && this.status == 200) {
var myObject = JSON.parse(this.responseText);
w3DisplayData("table", myObject);

var p1 = $( "#pass" ).val();
var p2 = $( "#ulpass" ).val();
if(p1 != p2){
alert("Konfirmasi password salah, silahkan ulang kembali");

data = {
'nopersonel' : $('input[name=nopersonel]').val(),
'pass': $('input[name=pass]').val(),
'ulpass': $('input[name=ulpass]').val(),
'gateid': $('input[name=gateid]').val()


$.post("tambahadmin.php", data, function(respone){







$nopersonel = $_POST["nopersonel"];
$password =$_POST["pass"];
$gate =$_POST["gateid"];

$mysqli = new mysqli();

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error()); //this will print out the error while connecting to MySQL, if any

$sql="SELECT nama,telp FROM pegawai WHERE nopersonel='$nopersonel' limit 1";

if ($result = mysqli_query($mysqli, $sql)) {

/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
$nama = $row['nama'];
$telp = $row['telp'];

$nama = array_values($nama);
$telp = array_values($telp);

$sql="INSERT INTO admin VALUES ($nopersonel,$password,$nama[0],$gate,$telp[0]);";
mysqli_query($mysqli, $sql)

/* free result set */

/* close connection */

echo "Berhasil tambah admin";


this is my first time building a website, can someone point out my mistake ?


You need to use .preventDefault to disable your browser's default behavior:

       //Your code here