My server code is returning json data, which have select mysql query. Now I have to parse this information and I need to fill there json information into table, How I will do that?
My server code
<?php
header('Access-Control-Allow-Origin: *');//Should work in Cross Domaim ajax Calling request
mysql_connect("localhost","root","2323");
mysql_select_db("service");
if(isset($_POST['type']))
{
if($_POST['type']=="carpenter"){
$startDate=$_POST['startDate'];
$endDate=$_POST['endDate'];
$query="select * from booking where scheduledDate between $startDate AND $endDate";
$result=mysqi_query($query);
$count=mysql_num_rows($result);
$retVal=array();
while($row=mysqli_fetch_assoc($result)){
$$retVal[]=$row;
}
echo json_encode($retVal);
}
} else{
echo "Invalid Format";
}
My script
<script>
function fetchData2(){
$(".data-contacts2-js tbody").empty();
var startDate=$('#datepicker1').val();
var endDate=$('#datepicker2').val();
$.ajax({
url: "http://localhost/service/cleaning.php",
type:"POST",
dataType:"json",
data:{type:"carpenter", startDate:startDate, endDate:endDate},
ContentType:"application/json",
success: function(response){
alert(obj);
},
error: function(err){
alert("fail");
}
});
}
$(document).ready(function(){
$(".data-contacts2-js tbody").empty();
$('#fetchContacts2').click(function() {
fetchData2();
});
});
</script>
My html code
<div class="block-content collapse in">
<div class="span12">
<table class="data-contacts2-js table table-striped" >
<thead>
<tr>
<th>ID</th>
<th>Customer Name</th>
<th>Customer Mobile</th>
<th>Customer Email</th>
<th>Address</th>
<th>Date</th>
<th>Time</th>
<th>Status</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<button id="fetchContacts2" class="btn btn-default" type="submit">Refresh</button>
</div>
My Json format is
[
{
"b_id": "101",
"cust_name": "qwq",
"cust_mobile": "323232323",
"cust_email": "u@gmail.com",
"cust_address": "kslaksl",
"scheduledDate": "2015-02-26",
"scheduledTime": "14:30:00",
"sc_id": "3",
"sps_id": "1"
}
]
My dataBase table: