PDA

View Full Version : سوال: مشکل در ساخت فرم داینامیک Ajax



پیام حیاتی
جمعه 14 خرداد 1395, 15:07 عصر
سلام عزیزان من در حال یادگیری ساخت یک فرم داینامیک هستم ، همه چیز رو طبق فیلم آموزشی انجام میدم ولی خروجی ندارم جدول نمایش داده نمی شود ، خطایی هم نیست.
تصویر فرمی که باید ساخته شود:

140675

فایل index.php :




<html>
<head>
<script type="text/javascript" href="js/bootstrap.min.js"></script>
<script type="text/javascript" href="jquery-2.2.4.min.js"></script>
<title>Dynamic Form Ajax</title>
</head>


<body>
<div class="container">
<br />
<div class="table-responsive">
<h3 align="center">Live Table Add Edit Delete using Ajax jQuery in PHP Mysql</h3><br />
<div id="live_data"></div>


</div><!-- End Table -->






</div><!-- End Container -->


</body>


</html>


<script>
$(document).ready(function(){
function fetch_data()
{
$.ajax({
url:"select.php",
method:"POST",
success:function(data){
$('#live_data').html(data);
}
});
}


fetcch_data();
$(document).on('click','#btn_add', function(){


var fist_name = $('#first_name').text();
var last_name = $('#last_name').text();
if(first_name == '')
{
alert("Enter First Name");
return false;
}
if(last_name == '')
{
alert("Enter Lost Name");
return false;
}
$.ajax({
url:"insert.php",
method:"POST",
data:{first_name:first_name, last_name:last_name},
dataType:"text",
success:function(data){
alert(data);
fetcch_data();
}
});
});




});
</script>


فایل select.php :


<?php
$connect=mysqli_connect("localhost", "root", "", "dynamicform");
$output='';
$sql="SELECT * FROM tbl_sample ORDER BY id DESC";
$result=mysqli_query($connect, $sql);


$output .='
<div class="table-responsive">
<table class="table table-border">
<tr>
<th width="10%">Id</th>
<th width="40%">First Name</th>
<th width="40%">Last Name</th>
<th width="10%">Delete</th>
</tr>';


if(mysqli_num_rows($result) > 0)
{
while($row=mysqli_fetch_array($result))
{
$output .='<td>'.$row["id"].'</td>
<td class="first_name" data-id1="'.$row["id"].'"
contenteditable>'.$row["first_name"].'</td>
<td class="last_name" data-id2="'.$row["id"].'"
contenteditable>'.$row["last_name"].'</td>
<td><button name="btn_delete" id="btn_delete"
data-id3="'.$row["id"].'">X</button></td>
';
}


$output .='<tr>
<td></td>
<td id="first_name" contenteditable></td>
<td id="last_name" contenteditable></td>
<td></button name="btn_add" id="btn_add" class="btn btn-xs btn-success">+</td>
</tr>';


}
else
{
$output .='<tr>
<td colspan="4">Data not Found</td>
</tr>';
}


$output .='</table>
</div>';
?>

تشکر.

numberone1
جمعه 14 خرداد 1395, 15:32 عصر
$output باید echo کنی :گیج: