AJAX function
var stopTime = 0;
var checkRequApprove = function ()
{
$.ajax({
url: 'http://127.0.0.1/ProgVsProg/main/checkApproveReq',
success:function(output){
jsn=JSON.parse(output);
if(output==false){
stopTime = setTimeout(checkRequApprove, 3000);
}
else {
bootbox.dialog({
message: "Battle",
title: "Request Accepted",
buttons:
{
success: {
label: "Approve",
className: "btn-success",
callback: function() {
$.ajax({
"type" : "POST",
"url" : "finalBattleApprove",
"data" : {'username' : jsn.user_name},
success: function(data){
$('#example').html(data);
$('#loadingmessage').show();
}
});
}
},
}
}
});
}
stopTime = setTimeout(checkRequApprove,3000);
Controller
public function checkApproveReq(){
$id = $this->session->userdata('userID');
$requApprove = '1';
$check = $this->lawmodel->checkRequApprove($id,$requApprove);
foreach($check as $row){
if($row->requApprove == '1')
{
$reqID = $this->lawmodel->getID($row->requestedID);
foreach($reqID as $row){
echo json_encode(
array(
'user_name' =>$row->username,
)
);
}
}
else
echo false;
}
}
I have this code wherein there is a realtime check to the database and if the condition has meet..custom dialog will pop up.
Im having this problem on my checkRequApprove function..The bootbox.dialog will not showup if the condition is meet in the controller...
i believe that my problem is because in the controller which echo json_encode. I cant find any solution .im still a newbie in ajax..
EDITED the custom dialog will only show after i refresh the page.
json_encodein controller intoecho $idthe dialog box will show..but i cant continue coz in my callback: will get a value fromjson_encode.