I'm designing an admin panel full Ajax and i have a problem... In a Page i select information db with ajax like this :
html
<body>
<div id="loadbox"></div>
<script src="jquery.js"></script>
<script src="script.js"></script>
</body>
js
$(document).ready(function() {
show_all();
});
function show_all() {
work = "select";
$.ajax({
type: "POST",
url: "server.php",
data: "work=" + work,
success: function(data) {
$("#loadbox").html(data);
}
});
}
and server.php file :
$pdo = new PDO('mysql:host=localhost;dbname=test','root','');
if(isset($_POST['work'])){
$work = $_POST['work'];
if ($work == 'select') {
$query = $pdo->query("SELECT * FROM t1");
while ($s = $query->fetch()) {
$name = $s['name'];
$family = $s['family'];
echo '<div id="xRight">'.$name.'</div>';
echo '<div id="xLeft">'.$family.'</div><br>';
}
}
}
Now I need to use the id xRight for this cod :
$("#xRight").click(function(){
$(this).addClass("vv");
});
But because div and id made in server.php file . id to be not found for use
How can I fix this problem ?!