Cakephp Ajax post数据在集合方法中不起作用
我正在尝试将一个数据从一个视图发送到另一个控制器,并为另一个视图设置数据。这里是ajax代码运行良好Cakephp Ajax post数据在集合方法中不起作用,ajax,cakephp,cakephp-2.6,Ajax,Cakephp,Cakephp 2.6,我正在尝试将一个数据从一个视图发送到另一个控制器,并为另一个视图设置数据。这里是ajax代码运行良好 $.ajax({ url: "<?php echo Router::url(array('controller'=>'users','action'=>'exchange_process'));?>", type: "POST", data: {"poin
$.ajax({
url: "<?php echo Router::url(array('controller'=>'users','action'=>'exchange_process'));?>",
type: "POST",
data: {"point_origin": point_origin },
success: function(){
alert("success");
}
});
从另一个角度来看,我已经尝试过了
<?php echo $pointorg ?>
它在起作用,但如果我尝试
public function exchange_process()
{
if($this->request->is(array('post', 'ajax'))) {
// $point_origin=$_POST['point_origin'];
$point_origin=123;
}
$this->set("pointorg",$point_origin);
}
它不起作用。将if子句更改为:
if($this->request->is('post') || $this->request->is('ajax')) {
CakePHP 2.3不支持类型头数组,请检查
http://book.cakephp.org/2.0/en/appendices/2-4-migration-guide.html#cakerequest
如果仅使用Ajax发送请求,则需要单独检查或仅使用Ajax。根据您给出的示例,我的第一个猜测是if条件永远不会为真,因此永远不会设置pointorg变量。您是否尝试过在请求类型检查中调试?另外,使用$this->request->data从请求中检索数据更有意义。对于检索数据,您可以给我提供一个示例吗?用于ajax请求的用户firebug。它将告诉您responseHere问题仅在条件变量inside condition not working,变量Out of condition working中出现。我在我的问题中给出了一个示例。是的,问题在于它不支持cakephp 2.3中的数组,但它支持cakephp 2.6中的cake 2.3中的数组,它将始终响应false。
if($this->request->is('post') || $this->request->is('ajax')) {
http://book.cakephp.org/2.0/en/appendices/2-4-migration-guide.html#cakerequest