我认为你的问题出在网址中,因为“meers/client”不是路线
$.ajax({
type: 'POST',
url: "<?php echo $this->Html->url(array('controller' => 'YourController','action' => 'YourAction')); ?>",
datatype:'json',
cache: false,
data: {myVal:'Success!'},
success: function(){alert('AjaX Success')},
error: function(){alert('AjaX Failed')}
})
.done(function(){
alert('AjaX Done!');
});
或者可以探测给出路由器:
$.ajax({
type: 'POST',
url: "<?php echo Router::url(array('controller' => 'YourController', 'action' => 'YourAction'), true); ?>",
datatype:'json',
cache: false,
data: {myVal:'Success!'},
success: function(){alert('AjaX Success')},
error: function(){alert('AjaX Failed')}
})
.done(function(){
alert('AjaX Done!');
});
你可以看到其他例子:
http://www.dereuromark.de/2014/01/09/ajax-and-cakephp/ http://www.dereuromark.de/2014/01/09/ajax-and-cakephp/
在 cakephp 2.x 中从视图到控制器进行 jquery ajax 调用 https://stackoverflow.com/questions/18440905/making-jquery-ajax-call-from-view-to-controller-in-cakephp-2-x