[eluser]bondjp[/eluser]
So my problem is that ajax only works when i click "nextweeklink" link for the first time, it updates the table with next week's appointments and then stops working when i try and click again "nextweeklink" but firebug says script was OK.
Thanks
ResultsView
Code:
[removed]
$(document).ready(function(){
$(function () {
$('#nextweeklink').livequery('click',function() {
$('<div id="resultdr">').load('searchresults/ajax_nextweek #result_dr', function() {
$(this).hide('#resultdr').replaceAll('#resultdr') ;
});
return false;
});
});
[removed]
</head>
<body>
............
<div id="resultdr">
<hr>
<table class="search_results" id="search_results" >
<thead id="thead">
<tr class="table_head" id="table_head">
<?php $weekdates=substr($WeekDate[1],8,2);
if ($weekdates>$lowEnd){?>
<th class="prev_week" id="prev_week">
<a class="prevWeekLink" id="prevweeklink" rel="nofollow" title="search prev week">Prev. Week</a>
</th>
<?php } else {?>
<th>
</th>
<?php }?>
<th class="calendar">
<span class="day">Monday</span>
<span class="date"><?php echo $WeekDate[1];?></span>
</th>
<th class="calendar">
<span class="day">Tuesday</span>
<span class="date"><?php echo $WeekDate[2];?></span>
</th>
..............................................
<th class="next_week">
<a class="nextWeekLink" id="nextweeklink" rel="nofollow" title="search next week">Next Week</a>
</th>
</tr>
</thead>
<?php foreach($docs as $row):
$name=$row->name;
$addr=$row->address;
$doc_id=$row->doctor_id;
<tbody>
<tr>
<td class="calendar" id="calendar" rowspan="1">
</td>
<td class="calendar alt" id="monday" rowspan="1">
<div>
<?php
//get appointments
foreach($timeslots as $row):
$date=$row->data;
$docid=$row->doctor_id;
$date = substr($date, 0, 10);
if ($doc_id==$docid){
if ($WeekDate[1]==$date){?>
<center>
<?php
$date=$row->data;
$date=substr($date,11,5);
echo anchor ($date,$date);?>
</center>
<?php }
}
endforeach;?>
</div>
</td>
<td class="calendar" id="tuesday" rowspan="1">
<div>
<?php
foreach($timeslots as $row):
$date=$row->data;
$docid=$row->doctor_id;
$date = substr($date, 0, 10);
if ($doc_id==$docid){
if ($WeekDate[2]==$date){?>
<center>
<?php
$date=$row->data;
$date=substr($date,11,5);
echo anchor ($date,$date);?>
</center>
<?php }
}
endforeach;?>
</div>
</td>
........................................
</tr>
</tbody>
<?php endforeach;?>
</table>
<?php echo $this->pagination->create_links(); ?>
</div>
ajax_nextweek Controller
Code:
//pagination
.............
$this->pagination->initialize($config);
//get the day number for calculating next week
$query=$this->uri->segment(3);
$data['datas']=$this->Results->getDatasNextweek($query);
......................
$this->load->vars($data);
$this->load->view('ajax_timeslots', $data);
}
Ajaxview - ajax_timeslots view (It will replace my calendar appointments)
Code:
<div id="result_dr">
<?php foreach($datas as $row):
$datais=$row;//current day value from ajax_nextweek controller
endforeach;?>
<?php //calculate day of the week
//$lowEnd=date("w");
$lowEnd=$datais;
$highEnd=$lowEnd+7;
$weekday=0;
for ($i=$lowEnd; $i<=$highEnd; $i++) {
$WeekDate[$weekday]=date("Y-m-d",mktime(0, 0, 0, date("m") , date("d")+$i, date("Y")));
$weekday++;
}
?>
<table class="search_results" id="search_results" >
<thead id="thead">
<tr class="table_head" id="table_head">
<?php $weekdates=substr($WeekDate[1],8,2);
if ($weekdates>$lowEnd){?>
<th class="prev_week" id="prev_week">
<a class="prevWeekLink" id="prevweeklink" rel="nofollow" title="search prev week">Prev. Week</a>
</th>
<?php } else {?>
<th>
</th>
<?php }?>
<th class="calendar">
<span class="day">Monday</span>
<span class="date"><?php echo $WeekDate[1];?></span>
</th>
..............................................
<th class="next_week">
<a class="nextWeekLink" id="nextweeklink" rel="nofollow" title="search next week">Next Week</a>
</th>
</tr>
</thead>
<?php foreach($docs as $row):
<tbody>
...........// equals to ResultsView <Tbody>
</tbody)
<?php endforeach;?>
</table>
<?php echo $this->pagination->create_links(); ?>
</div>