soma80 Posted March 6, 2009 Share Posted March 6, 2009 Veiw File .. forms.ctp <?php echo $javascript->link('jquery',false); echo $form->create('User', array('default' => false)); ?> <div class='form2'> <div class='lable2'> <?php echo $form->label('Enter Email'); ?> </div> <?php echo $form->text('email',array('class' => 'input')); ?> <p> <?php echo $form->submit('Send',array('class' => 'but2', 'onclick'=>' $.post("/Users/forms",{email:"admin@localhost"}, function(data){ alert('OK'); }); ' )); echo $form->submit('Cancel',array('class' => 'cancel','onclick'=>'self.parent.tb_remove()')); ?> </p> <div id="#message"> <div/> </div> <?php echo $form->end(); ?> Controller File <?php class UsersController extends Appcontroller{ var $name='Users'; var $helpers = array('Form','Javascript','Html','Ajax'); var $components = array('Cookie','Email','RequestHandler'); function forms() { $this->pageTitle = 'Home'; $this->layout = 'space'; if (!empty($this->data)) { if($this->RequestHandler) { if(($user = $this->User->validateEmail($this->data['User'])) == true) { $this-> __sendNewUserMail(); $this->set('data','ok'); } else { $this->Session->setFlash('عفواً.. المعلومات التي ادخلت غير صحيحة .','fail_message'); } } } if (empty($this->data)) { $this->User->create(); } } function __sendNewUserMail() { /* SMTP Options */ $this->Email->smtpOptions = array( 'port'=>'25', 'timeout'=>'30', 'host' => 'localhost', ); /* Set delivery method */ $this->Email->delivery = 'smtp'; /* Do not pass any args to send() */ $this->Email->to =$this -> data['User']['email']; $this->Email->subject = 'Welcome to our really cool thing'; $this->Email->from = 'Cool Web App <[email protected]>'; $this->Email->send('Hello'); /* Check for SMTP errors. */ $this->set('smtp-errors', $this->Email->smtpError); } } ?> Th problem is The ajax not work when click submit button , but if I change ajax part by any thing like alert('???? '); the code excute .. Link to comment https://forums.phpfreaks.com/topic/148292-cakephp-jquery-ajax-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.