Skip to content

Instantly share code, notes, and snippets.

@andrebian
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrebian/9bebb88de11523c4c7ad to your computer and use it in GitHub Desktop.
Save andrebian/9bebb88de11523c4c7ad to your computer and use it in GitHub Desktop.
<!-- View -->
<script>
$.ajax({
type: 'post',
url: '<?php echo Router::url(array('controller' => 'x', 'action' => 'y')); ?>',
data: 'chave=valor&chave2=valor2',
success: function(data){
alert(data);
},
error: function(a, b, c){
console.log(a);
console.log(b);
console.log(c);
}
});
</script>
<!-- Controller -->
<?php
class XController extends AppController {
public function y() {
$this->request->allowMethod('ajax');
$item1 = $this->request->data['chave'];
$item2 = $this->request->data['chave2'];
// agora só tratar tudo
// parar a execução, afinal de contas é uma chamada assíncrona e deve ser finalizada
die();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment