Cakephp4.x AjaxからのPOSTにアクセスできない対処
Cakephp3.xでは下記URLの記事を参考にアクセスできていたのすが、4.xだと空になってしまう。
4.xでは、Json、XMLで入力されたデータにアクセスする場合、オプション機能でそれをデコードが必要でした。
CakePHP + AjaxでのPOSTで受け取った情報が空になる原因
https://blog.supersonico.info/?p=3172
Cakephp 3.x
cakephp3.x&sample.php
//セキュリティコンポーネントを一時無効
if ($this->params['action'] == アクション名) {
$this->Security->csrfCheck = false;
$this->Security->validatePost = false;
}
//getDate()で受け取り
$post_data = $this->request->getData();
Cakephp 4.x
cakephp4.x&sample.php
//セキュリティコンポーネントを一時無効
if ($this->params['action'] == アクション名) {
$this->Security->csrfCheck = false;
$this->Security->validatePost = false;
}
//input()のオプション機能でデコードし受け取り
$post_data = $this->request->input('json_decode');
参考:
リクエストとレスポンスオブジェクト
PUT、PATCH または DELETE データ
https://book.cakephp.org/4/ja/controllers/request-response.html
Author And Source
この問題について(Cakephp4.x AjaxからのPOSTにアクセスできない対処), 我々は、より多くの情報をここで見つけました https://qiita.com/nava/items/5f3d37efb3040aab58e2著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .