javascript - Grab a form data with ajax -
i'm trying simple form mail ajax. but, can't grab data form.
my form:
<?php echo $this->form->create('page', array('default' => false)); ?> <?php echo $this->form->input('texto', array('label' => false, 'type' => 'textarea)); ?> <?php echo $this->form->submit('enviar', array('id' => 'enviar')); echo $this->form->end();
my ajax:
$(document).ready(function() { $('#enviar').click(function(){ $.ajax({ type: 'post', complete: function(r){ $('div.teste').html('<h4> enviado!</h4>'); } }) }) });
the controller:
if($this->request->is('ajax')) { debug($this->request->data); app::uses('cakeemail', 'network/email'); $email = new cakeemail('gmail'); $email->to('xxxx@gmail.com'); $email->subject('nova mensagem - site althi'); $email->send($mensagem); } }
and controller send email. e-mail has send sucefull, data of this->request->data
blank array. think problem data passed ajax. can me please?
you have set data
value in ajax function call.
$.ajax( thecontrollerurl, {data: $("#theformid").serialize()} );
more info here: http://api.jquery.com/jquery.ajax/
Comments
Post a Comment