Created
November 5, 2012 00:51
-
-
Save wenbert/4014610 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## the Controller | |
<?php | |
class FormfieldsController extends AppController { | |
public $helpers = array('Html', 'Form', 'Formfield'); | |
public $components = array('RequestHandler'); | |
public function beforeFilter() { | |
parent::beforeFilter(); | |
$this->Security->csrfExpires = '+1 hour'; | |
if($this->Auth->user('role') === 'admin' || $this->Auth->user('role') === 'user') { | |
$this->Auth->allow('*'); | |
} | |
$this->Security->unlockedActions = array('addrow'); | |
} | |
/** | |
* handles AJAX requests to save a formrow | |
* return JSON | |
* | |
*/ | |
public function addrow() { | |
$result = array(); | |
if($this->request->is('ajax')) { | |
$result['status'] = 'success'; | |
$result['message'] = __('Row added'); | |
} | |
$this->set('result', $result); | |
} | |
} | |
## the view part with the AJAX | |
$.ajax({ | |
'type': 'POST', | |
'cache': false, | |
'dataType': 'json', | |
'url': appUrl+'/formfields/addrow.json', | |
'success': function(data) { | |
console.log('success'); | |
}, | |
'error': function(jqXHR, textStatus, errorThrown) { | |
}, | |
'complete': function(data) { | |
console.log('complete.'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment