0

I've set up cake php for ajax and json-requests using mostly this turtorial: http://book.cakephp.org/2.0/en/views/json-and-xml-views.html

Everything is working fine, but if I make a post request (in this case for using cakephp with json-rpc), Cake enters an infite Loop saveing hundreds of empty entries in my database until it finally runs out of memory even if my controller and is completly empty, as long there is some json-output (even an 505 error message works). Is this due to automagic? I am able to save data as intentend, when I pass data which is properly set up to fit the model. But if send anything else (just params or empty data for example) I enter this infite loop.

Even if my posts contain errors, I think this should not happen.

Here is the error message:

<b>Fatal error</b>:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 71 bytes) in <b>/var/www/****/cake/lib/Cake/Controller/Controller.php</b> on line <b>333</b><br />

Here is my call with jquery:

$.ajax({
        url: '/dezem/cake/users.json', //even if I send the data to user without the json extension, the same happens...
        type: 'POST',
        dataType: 'json',
        data: '{"method": "echo", "params": ["Hello JSON-RPC"], "id": 1}',
        success: function(){alert("YEEHHEHAAW")},
        error: function(){alert("Nööööööööööööööö")}
    })

As requested here the Code inside my controller:

class UsersController extends AppController {
public $helpers = array('Js', 'Html');
public $components = array('RequestHandler');
....

public function index() {       
    $this->User->recursive = -1;

    $users = $this->User->find('all');
    if($this->RequestHandler->isAjax()){
        $this->autoLayout = $this->autoRender = false;      
        if ($this->request->is('post')){
            $this->set(array(
                'data' => $users,
                '_serialize' => array('data')
            ));
            $this->render('/layouts/json');
        }   
        else if ($this->request->is('get')) {           
                $this->set(array(
                   'data' => $users,
                    '_serialize' => array('data')
                ));
                $this->render('/layouts/json');
        }
    }
}
}

As I said, an empty controller leads to the same result:

    public function index() {
    }
hugo der hungrige
  • 12,382
  • 9
  • 57
  • 84
  • Also post the code in your controller, that handles the request. – joshua.paling Aug 20 '12 at 23:42
  • 1
    Try with the option `async:false` in your ajax function. Also you can try to prevent the default event in beforeSend() `e.preventDefault();` – Arun Jain Aug 21 '12 at 04:26
  • @Arun Jain: Thx but setting async:false doesnt change anything. Using e.preventDefault is not really an option, as I want to send other informations to the server.. – hugo der hungrige Aug 23 '12 at 17:14
  • have u tried firebug ? ... hope it helps to trace your error. Also check log file cake log as well as apache logs .. – anasanjaria Feb 06 '13 at 12:17

0 Answers0