我正在使用 jQuery 向某些控制器操作发出 AJAX 请求。该请求是通过同一控制器中编辑操作视图中的按钮激活的。
我的问题:
Ajax 请求返回编辑视图的所有代码(包含所有表单和输入),而不是预期的数量。如果我将相同的 ajax 按钮放在添加操作的视图中,它会完美工作(它返回数字)。
编辑和添加操作保持默认生成的状态(使用烘焙)。
这是发出 ajax 请求的 jQuery 函数
$.ajax({
type: 'POST',
url: 'checkTargets',
data: {target: tgt_array, channel: channel_type},
success:function(data){
$('#num_subscribers > span').html(data);
},
error:function(){
$('#num_subscribers > span').html("The subscribers could not be loaded");
},
timeout: 5000
});
}
这是动作
function checkTargets() {
if ($this->RequestHandler->isAjax()) {
if(!empty($this->params['form'])) {
$data = $this->params['form'];
if ($data['channel'] === 'SMS') {
$channel = 'sms';
} else {
$channel = 'pin';
}
$targets = $this->processPostTargets($data['target']);
$this->RequestHandler->respondAs('text');
//This echo a NUMBER
echo ClassRegistry::init('Selection')->countSubscribersInTarget($channel, $targets);
Configure:: write('debug', 0);
$this->autoRender = false;
exit();
}
}
}
为什么会发生这种情况?
Thanks
只是一个建议,无法访问所有内容,您尝试过吗?
$this->autoRender = false;
$this->layout = 'ajax';
另外我建议保持简单:
$.post("/controller/checkTargets", function(data) {
alert(data);
}
function checkTargets() {
$this->autoRender = false;
$this->layout = 'ajax';
echo "Im working";
}
然后从那里开始。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)