fnReloadAjax issue
fnReloadAjax issue
rage10940
Posts: 48Questions: 0Answers: 0
Hello Allan, I came across a problem with fnReloadAjax.
The problem :
>> When two different computers are on the same page using fnReloadAjax on the same table when some one alters the data for example say when column = 3 instead of 2 the data in the first client that initiated the change is gone (which should work) but in the second client / computer the old data where is still there.
When I say still there, I mean that since the value of column is not 2 any more (it is 3) the data should not be showing in that table, but the second client still has the data shown on the table.
Possible issue (that I can think of?) :
One minute the fnReloadAjax is in fact retrieving the JSON data, but when the JSON data is not present any more (when the column value now equals 3 rather then 2) the data on the second client still shows up on that table (when it shouldn’t').
When I go home tonight I will turn my server on and hopefully you can have a look at it. I will also upload a video and put it on this thread to show you in more detail the issue.
For the mean time my code is :
[code]
function ajaxcall() {
$this->load->model('queue_model');
$data['waiting'] = $this->queue_model->waiting();
$data['beingseen'] = $this->queue_model->beingseen();
$this->output->set_header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
}
[/code]
[code]
$(document).ready(function()
{
var table1 = $('#waiting').dataTable(
{
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"iDisplayLength": 10,
"aLengthMenu": [5, 10],
"sAjaxDataProp": "waiting",
"sAjaxSource": '<?php echo base_url();?>studentqueue_controller/ajaxcall',
"bDeferRender": true,
"bAutoWidth": false,
"aoColumns":
[
{"mdata": "id",
"sWidth": "7%",
"mRender": function(data, full)
{
var div = '';
var url = '' + '' + '' + '' + data + '';
}
},
{"mdata": "first"},
{"mdata": "last"},
{"mdata": "SECOND",
"sWidth": "1%"
},
{"mdata": "reason"},
{"mdata": "studentcomments"},
{"mdata": "aidyear",
"sWidth": "1%"
},
{"mdata": "counselorcomments"}
]
});
setInterval(function() {
table1.fnReloadAjax(null, null, true);
}, 1000);
});
$(document).ready(function()
{
var table2 = $('#beingseen').dataTable(
{
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"iDisplayLength": 10,
"aLengthMenu": [5, 10],
"sAjaxDataProp": "beingseen",
"sAjaxSource": '<?php echo base_url();?>studentqueue_controller/ajaxcall',
"bDeferRender": true,
"bAutoWidth": false,
"aoColumns":
[
{"mdata": "id",
"sWidth": "1%",
"mRender": function(data, full)
{
var div = '';
var url = '' + '' + '
The problem :
>> When two different computers are on the same page using fnReloadAjax on the same table when some one alters the data for example say when column = 3 instead of 2 the data in the first client that initiated the change is gone (which should work) but in the second client / computer the old data where is still there.
When I say still there, I mean that since the value of column is not 2 any more (it is 3) the data should not be showing in that table, but the second client still has the data shown on the table.
Possible issue (that I can think of?) :
One minute the fnReloadAjax is in fact retrieving the JSON data, but when the JSON data is not present any more (when the column value now equals 3 rather then 2) the data on the second client still shows up on that table (when it shouldn’t').
When I go home tonight I will turn my server on and hopefully you can have a look at it. I will also upload a video and put it on this thread to show you in more detail the issue.
For the mean time my code is :
[code]
function ajaxcall() {
$this->load->model('queue_model');
$data['waiting'] = $this->queue_model->waiting();
$data['beingseen'] = $this->queue_model->beingseen();
$this->output->set_header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
}
[/code]
[code]
$(document).ready(function()
{
var table1 = $('#waiting').dataTable(
{
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"iDisplayLength": 10,
"aLengthMenu": [5, 10],
"sAjaxDataProp": "waiting",
"sAjaxSource": '<?php echo base_url();?>studentqueue_controller/ajaxcall',
"bDeferRender": true,
"bAutoWidth": false,
"aoColumns":
[
{"mdata": "id",
"sWidth": "7%",
"mRender": function(data, full)
{
var div = '';
var url = '' + '' + '' + '' + data + '';
}
},
{"mdata": "first"},
{"mdata": "last"},
{"mdata": "SECOND",
"sWidth": "1%"
},
{"mdata": "reason"},
{"mdata": "studentcomments"},
{"mdata": "aidyear",
"sWidth": "1%"
},
{"mdata": "counselorcomments"}
]
});
setInterval(function() {
table1.fnReloadAjax(null, null, true);
}, 1000);
});
$(document).ready(function()
{
var table2 = $('#beingseen').dataTable(
{
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"iDisplayLength": 10,
"aLengthMenu": [5, 10],
"sAjaxDataProp": "beingseen",
"sAjaxSource": '<?php echo base_url();?>studentqueue_controller/ajaxcall',
"bDeferRender": true,
"bAutoWidth": false,
"aoColumns":
[
{"mdata": "id",
"sWidth": "1%",
"mRender": function(data, full)
{
var div = '';
var url = '' + '' + '
This discussion has been closed.
Replies
http://www.youtube.com/watch?v=Dod5Rznj6BQ
I will also keep my server up tonight, and the login is the same as before, if my IP changed I will send you notification!
Thanks Allan,
Hopefully this is a small issue.
If you have a look at the fnReloadAjax plug-in, you will see that it calls fnClearTable followed by fnAddData - so my guess is that the Ajax request is getting incorrect data back (i.e. it is reporting a row when it shouldn't be).
Allan
Uncaught TypeError: Cannot read property 'length' of null
and
Uncaught TypeError: Cannot read property 'length' of null
http://www.freeimagehosting.net/wh71n
Allan
Allan
I was sending a NULL value to the datatables so it was always looking for data saying Loading Data.... when there was none.
So in my query :
[code]
function waiting() {
$sql = "SELECT DISTINCT
session.session_id as id,
session.anum,
student.first,
student.last,
SEC_TO_TIME(TIMESTAMPDIFF(SECOND, signintime, NOW())) as SECOND,
reasons.reason,
session.studentcomments,
session.aidyear,
support.counselorcomments
FROM session
INNER JOIN student
ON student.anum = session.anum
LEFT JOIN support
ON session.session_id = support.session_id
INNER JOIN reasons
ON reasons.reason_id = session.why
LEFT JOIN support support2
ON support.session_id = support2.session_id
AND support.starttime < support2.starttime
WHERE session.status IN (0,2) AND support2.session_id IS NULL
ORDER BY id asc;";
$q = $this->db->conn_id->prepare($sql);
$q->execute();
if ($q) {
if ($q->rowCount() > 0) {
return $q->fetchall();
} else {
return $q = array(); // All I had to add was an empty array
}
}
}
[/code]
Literally two lines of code fixed this... One line for this query and another line for the other query. Thanks Allan!