AJAX w/ bootbox custom dialog
var checkRequApprove = function ()
{
$.ajax({
url: '127.0.0.1/ProgVsProg/main/checkApproveReq',
success:function(output){
if(output==false){
console.log(output);
stopTime = setTimeout(checkRequApprove, 1000);
}
else {
bootbox.dialog({
message: (output),
title: "Request Accepted",
buttons:
{
success: {
label: "Approve",
className: "btn-success",
callback: function() {
var username = (output);
$.ajax({
"type" : "POST",
"url" : "finalApprove",
"data" : {'username' : username},
success: function(data){
$('#example').html(data);
}
});
}
},
}
});
stopCounter();
}
}
});
}
stopTime = setTimeout(checkRequApprove,1000);
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 $row->username;
}
}
else
echo false;
}
}
public function finalApprove(){
$username = $this->input->post('username');
$userID = $this->session->userdata('userID');
$id = $this->lawmodel->getUsernameID($username);
$data= array(
"challApprove" => "1",
);
$this->lawmodel->finalUpdateRequest($userID,$id,$data);
echo "Accepting Please Wait!";
}
Im having this problem i dont know if im doing the correct way.. I want that the ajax response on checkRequApprove
will be call back in the custom dialog success buttons callback: function()
. I have put in the success button the response on checkRequApprove which is output
inside the var username
to be able to call back in the callback: function
.
Base on my code below it seems that the data:{'username' : username},
is not getting the value in var username
that make the success function return no output.
pls help..im new in ajax..:(
FIRST: the "output" var received by your success function is the whole jqXHR-Object. What you are searching is the responseText - in your case output.responseText
SECOND: On your Server File, you are echoing true. Since this is a HTML-response it comes as a String. So you have to check if( output === 'FALSE')
BTW: There are some more errors in your example. But i won't go to deep in here. I recommend to get an better understanding of the jqXHR-Object and Tools to inspect the browsers xhr-requests. like firebug or the native chrome devleoper toolbar
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.