Wednesday, 15 June 2011

ajax - method not allowed, when using onlyajax in controller action -



ajax - method not allowed, when using onlyajax in controller action -

background:

i'm attempting create restful apis in cakephp, , delegate front end end work front end end templating language handlebars. elicited here (http://www.dereuromark.de/2014/01/09/ajax-and-cakephp/) , using jsonview , making extensionful api approach.

problem:

allowing ajax using $this->request->onlyallow('ajax'); returning method not allowed. want enforce apis not straight called browser. could (the community) validate approach building such apis.

code:

//at controller public function joinwithcode() { //$this->request->onlyallow('ajax'); //returns 405 method not allowed //$this->request->onlyallow('post'); //works , not allow access browser $this->response->type('json'); $data = array( 'content' => 'something', 'error' => 'something else', ); $this->set(compact('data')); $this->set('_serialize', 'data'); } //routes.php router::parseextensions('json'); router::connect('/classrooms/join', array('controller' => 'classrooms', 'action' => 'joinwithcode'));

the post effort postman extension:

ajax cakephp

No comments:

Post a Comment