Last active
August 29, 2015 14:14
-
-
Save andrebian/9bebb88de11523c4c7ad 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
<!-- 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