0
好吧,所以我必须错过某些关键或基本的东西。我正在尝试创建一个使用JQuery/AJAX登录的登录元素。CakePHP 2.5 JQuery Ajax登录元素
在我的布局,我有:
//...
echo $this->Html->script('jquery'); // Include jQuery library
//...
if (AuthComponent::user('id')){
echo $this->element('userElement',array('username'=>AuthComponent::user('username')));
} else {
echo $this->element('loginElement');
}
echo $this->Js->writeBuffer();
UserElement只是说“你好$用户名”,当我转到/用户/登录手工登录工作正常/
这里是loginElement.ctp,我认为问题是:
<?php
$data = $this->Js->get('#UserForm')->serializeForm(array('isForm' => true, 'inline' => true));
$this->Js->get('#UserForm')->event(
'submit',
$this->Js->request(
array('action' => 'save'),
array(
'update' => '#loadingdiv',//what to update while ajaxing
'before' => "$('#loading').fadeIn();",//before request
'complete' => "$('#loading').fadeOut();",//when request complete
'data' => $data,
'async' => true,
'dataExpression'=>true,
'method' => 'POST',
)
)
);
?>
<div class="loadingdiv" id="loadingdiv"> </div>
<div class="users form">
<?php
echo $this->Session->flash('auth');
echo $this->Form->create('User',array('action' => 'save', 'default' => false));
?>
<fieldset>
<?php
echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?php
echo $this->Form->end(__('Login'));
echo $this->Js->writeBuffer();
?>
</div>
表单在浏览器控制台中没有做任何事情,没有登录,没有失败的javascript调用....没有。我错过了什么?