Last active
August 29, 2015 14:04
-
-
Save andrebian/9e69e665ce0cb7e4c639 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Isto é realizando uma chamada com o javascript convencional | |
<script> | |
$.ajax({ | |
type:"POST", | |
url:link, | |
data:dados, | |
dataType : 'json', | |
success:function(data){ | |
console.log('e retornou: '+data); | |
if(data==0){ | |
message.html(''); | |
message.append("Esse nome está disponível"); | |
} else { | |
message.html(''); | |
message.append("Esse nome já esta sendo usado"); | |
} | |
} | |
}); | |
</script> | |
Isto é realizando a mesma chamada com o Js Helper | |
<?php | |
// Primeriamente criamos o form desejado com os inputs necessários | |
echo $this->Form->create('Exemplo'); | |
echo $this->Form->input( | |
'Exemplo.campo', | |
array( | |
'label' => false, | |
'type' => 'select', | |
'options' => $options, // supondo que seja um select | |
'empty' => array( 0 => '-- Selecione uma opção --'), | |
) | |
); | |
$this->Form->end(__('Submit')); | |
?> | |
<div id="divASerAtualizada"></div> | |
<?php | |
// E agora temos a chamada pelo JS Helper de fato | |
$this->Js->get('#ExemploCampo')->event('change', // [chance, click ...] | |
$this->Js->request( | |
array('controller'=>'controllerDesejado', 'action'=>'actionDesejada'), | |
array( | |
'update'=>'#divASerAtualizada', | |
'async' => true, | |
'method' => 'post', | |
'complete' => 'algumaFuncaoEmJavascriptSeNecessario();', | |
'dataExpression' => true, | |
'data' => $this->Js->serializeForm(array( | |
'isForm' => true, | |
'inline' => true | |
)) | |
) | |
) | |
); | |
// No Controller | |
public function ajaxBuscaAlgo(){ | |
$this->request->onlyAllow('post'); | |
die(debug($this->request->data)); | |
} | |
// Prontinho, o conteúdo recebido através do post será impresso na div #divASerAtualizada, agora basta ser implementado o que for necessário. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment