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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -