I want a full admin panel Ajax write And a page that details of the bank called with Ajax... I poured this information on a div that performs the button off and on
my cod is :
HTML
<html>
<head>
<script src="file/js/Connection.js"></script>
</head>
<body>
<div class="row" id="box"></div>
</body>
</html>
Connection File js cod :
$(document).ready(function() {
show_all();
});
function show_all() {
work = "select";
$.ajax({
type: "POST",
url: "server.php",
data: "work="+work,
success: function(data) {
$("#box").html(data);
}
});
}
and file server.php :
<?php
$pdo = new PDO('mysql:host=localhost;dbname=Contact', 'root', '');
if (isset($_POST['work'])) {
$work = $_POST['work'];
if ($work == 'select') {
$qcomment = $pdo->query("SELECT * FROM myfeilds");
while ($XXX = $qcomment->fetch()) {
$Z1 = $XXX['id'];
$Z2 = $XXX['name'];
$Z3 = $XXX['active'];
echo '
<div class="col-lg-3">
<div class="row" id="back">
<div class="col-lg-8" id="Fname">
<span class="glyphicon glyphicon-check"></span>
<label>' . $Z2 . '</label>
</div>
<div class="col-lg-4" id="Fbtn"> ';
if ($Z3 == 1) { echo '
<div class="btn btn-on" id="' . $Z1 . '">
<div> <span class="glyphicon glyphicon-remove"></span></div>
<div><span class="glyphicon glyphicon-ok"></span></div>
</div>';
} else { echo '
<div class="btn btn-off" id="' . $Z1 . '">
<div> <span class="glyphicon glyphicon-remove"></span></div>
<div><span class="glyphicon glyphicon-ok"></span></div>
</div>';
} echo '
</div>
</div>
</div>
';
}
}
}
?>
And in the end I tried to write that off and turn on the javascript code
$(".btn").on('click',function(e){
if($(this).hasClass("btn-on")){
$(this).removeClass("btn-on");
$(this).addClass("btn-off");
}
else {
$(this).removeClass("btn-off");
$(this).addClass("btn-on");
}
});
And they told me because the select performed in an external file Then you must use this code to work correctly
$(document).on("click",".btn",function(event) {
if($(this).hasClass("btn-on")){
$(this).removeClass("btn-on");
$(this).addClass("btn-off");
}
else {
$(this).removeClass("btn-off");
$(this).addClass("btn-on");
}
});
This code works, but only the first time that I entered the Fever this page And if I get another tab and go back again, does not work...
what do I do :)