You know, I really confuse use jquery with codeigniter. I create a web application to monitoring a request form from user. I have a view on html that displayed a table like this :
+---------------+--------------------+
| id_request | comment_bapak |
+---------------+--------------------+
| 001 | |
| 002 | |
| 003 | |
+---------------+--------------------+
I was wondering to create some alert in jquery or javascript when the column 'comment_bapak' is inserted by user. So, i use autorefresh page on jquery.Let say, an user is inserted "This is comment of id_request 002" and then, on web will be displayed alert("Request 002 has inserted")
and the table would be refresh like this.
+---------------+---------------------------------+
| id_request | comment_bapak |
+---------------+---------------------------------+
| 001 | |
| 002 |This is comment of id_request 002|
| 003 | |
+---------------+---------------------------------+
So, this is my code
Model
public function getKomentarMD() {
$this->db->select('id_request, comment_bapak');
$query = $this->db->get('tbl_requestfix');
return $query->result_array();
}
Controller
public function getKomentarMD() {
$row = $this->model_request->getKomentarMD();
echo json_encode($row);
}
view
<td class="sorting1" id='no_request' data-id-reseh="<?php echo $data['id_request']; ?>"><?php echo $data['id_request']; ?></td>
<td class="center" id="tanggap_md"><?php echo $data['jawaban_bapak']; ?> /td>
Jquery
function refreshAkibatCommentMD() {
var temp[];
var requestMasuk = $('#tanggap_md').text();
var audioElement = document.getElementById('notif-md');
audioElement.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
setTimeout(function() {
$.ajax({
url: '<?php echo base_url() . 'control_closing/getKomentarMD/' ?>',
type: 'POST',
dataType: 'json',
success: function(obj) {
audioElement.play(); //playing tone
alert(obj.comment_bapak);// debugging
?? Please help...
refreshAkibatCommentMD();
}
});
}, 5000);
}
I have 2 question.
- Why alert(obj.comment_bapak) gives me undefined ?
- I think, I should create a new array on jquery as temporary to distinguish with new array that get from autorefresh ?
Any help and suggestion it so appreciated.
Update
-----------------------------------------------------------
I have two page, first is an user form and the second is monitoring page. Both page have a same table display. I meant, when user update a row on table, there will be a alert notification on monitoring page where the row has updated. So I use Jquery/Js to handle this.
I have an idea like this.
When monitoring page is load on first time, call all
id, comment_bapak
from database and save as first array object.With auto refresh on JS/Jquery, use ajax to call all
id, comment_bapak
from database and save as second array object. So, let say user has updated some row, there will be difference with first array object. Am I right ?Check all item on object. Find the different between two array, and when it found, it must be an alert notification ?
If success, change value first array objet with second array object. So on so on...
Do you have any idea ?