我正在提交一个带有 ajax 的表单,我正在尝试返回一个 json 响应。问题是我找回了丢失的视图。当我添加 autoResponder=false 时,我什么也得不到。我正在使用 cakephp 2.5
我在同一个控制器中有另一个动作,我可以得到一个 json 响应。我使用标准的 ajax 调用。此操作的不同之处在于我将表单数据与多部分一起使用。在另一个 ajax 调用中,我能够将扩展名 .json 添加到 url 以告诉 cakephp 使用该路由。
当我将 .json 添加到表单操作 url 时,我会收到缺少操作的响应。
<form action="/btstadmin/pages/ajax_edit.json/3" id="ajax_editJsonForm" enctype="multipart/form-data" method="post" accept-charset="utf-8">
回覆
The action <em>ajax_edit.json</em> is not defined in controller <em>PagesController
我的行动是
public function ajax_edit() {
if ($this->request->is('ajax')) {
if ($this->Page->save($this->request->data)) {
$this->RequestHandler->respondAs('json');
$this->set("status", "success");
$this->set("message", "All pages re-ordered");
$this->set("_serialize", array("status", "message"));
我的其他操作适用于:
$.ajax({
url: "/btstadmin/pages/reorder.json",
type: "post",
dataType:"json",
data: neworderSer,
我的动作给出了 json 响应
public function reorder() {
if ($this->Page->saveMany($data)) {
$this->set("status", "sucess");
$this->set("message", "All pages re-ordered");
$this->set("content", $data);
$this->set("_serialize", array("status", "message", "content"));
更新
我更改了表单创建
$formaction = '/pages/ajax_edit/'.$this->data['Page']['id'].'.json';
echo $this->Form->create('Page', array('type' => 'file', 'url' => $formaction));