[英]call ajax response to be use in custom dialog callback function
AJAX w/ bootbox custom dialog AJAX w / bootbox自定义对话框
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()
. 我有这个问题,我不知道我是否在做正确的方法..我希望对checkRequApprove
的ajax响应将在自定义对话框成功按钮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
. 我在成功按钮中放置了对checkRequApprove的响应,该响应在var username
内部output
,以便能够在callback: function
中进行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. 根据我下面的代码,似乎data:{'username' : username},
没有获得var username
中的值,该值使成功函数不返回任何输出。
pls help..im new in ajax..:( 请在Ajax中使用help..im新.. :(
FIRST: the "output" var received by your success function is the whole jqXHR-Object. 首先:成功函数接收到的“输出”变量是整个jqXHR-Object。 What you are searching is the responseText - in your case output.responseText
您正在搜索的是responseText-在您的情况下为output.responseText
SECOND: On your Server File, you are echoing true. 第二:在您的服务器文件上,您呼应为true。 Since this is a HTML-response it comes as a String. 由于这是HTML响应,因此它是字符串。 So you have to check if( output === 'FALSE')
所以你必须检查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. 我建议更好地了解jqXHR对象和工具以检查浏览器的xhr-requests。 like firebug or the native chrome devleoper toolbar 如萤火虫或本机chrome devleoper工具栏
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.