簡體   English   中英

CakePHP AjaxHandler-> respond()返回錯誤500

[英]CakePHP AjaxHandler->respond() returning Error 500

我面臨一個非常煩人的問題,我無法解決...

我目前在一個帶有三個獨立存儲庫的相當大的項目中使用PHP 5.6和CakePHP 2.3,每個存儲庫都使用一個不同的存儲庫。 我在Ubuntu上的Apache本地服務器上。

網站運行良好,我可以創建數據,更新和刪除數據,除非我將Ajax與POST HTTP方法結合使用。 當我這樣做時, 請求被執行 (數據被編輯/創建/刪除),但是函數$this->AjaxHandler->respond('json'); 什么也不返回,這將導致我的ajax出現HTTP錯誤500,等待響應。

我的Apache日志和CakePHP日志中都沒有錯誤消息。

我的控制器

<?php

public function edit($id = null) {

    $this->ClientPayment->id = $id;
    $this->ClientPayment->save($this->request->data)

    if ($this->request->is('ajax')){
        $this->AjaxHandler->response(true, $this->ClientPayment->read(),__('The client payment has been saved'));
        // At this point, everything went fine, clientPayment was saved
        // and $this->ClientPayment contain everything we need

        $this->AjaxHandler->respond('json');
    }

我的ajax腳本

<script>
    $(function() {
        $("#ClientPaymentEditForm").submit(function( event ) {
            ajaxSubmitForm($(this), function(data){
        });
        event.preventDefault();
    });
});
</script>

我真的很困惑,因為此代碼在登台/產品服務器上使用,並且可以正常工作,好像我的Apache安裝或PHP安裝錯誤(缺少插件,跨域請求等),但我進行了搜索對於所有已知問題,似乎沒有任何效果。

如果有人有一些調試的想法或想法,我可以收集各種信息!

在此先感謝一下,我確實為此苦了一段時間。

首先,我首先與Postman進行了測試,我可以向您展示這是我的方法,在我推薦使用Postman的前端之前,在發送ajax數據之后。

   public function edit()
    {
      $data = ['result' => 'fail', 'id' => 'null'];
      $errors = $this->ClientPayment->validator()->errors($this->request->getData());
      if(empty($errors))
      {
          $clientPayment = $this->ClientPayment->newEntity($this->request->getData());

          //You can get the data sent with your variables and assign them to their correct variables

          $clientPayment->id = $this->request->getData('id');
          $clientPayment->name = $this->request->getData('name');

          if ($this->ClientPayment->save($clientPayment))
          {
              $this->set([
                    'success' => true,
                    'data' => $clientPayment,
                    '_serialize' => ['success', 'data']
                ]);
          }
      } else {

          $data['error'] = $errors;
      }
      $this->set(compact('data'));
      $this->set('_serialize', ['data']);


    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM