Form is like that…
<form id="login-form" class="navbar-form pull-right">
<input type="text" class="span2" placeholder="Username">
<input type="password" class="span2" placeholder="Password">
<?php
echo CHtml::ajaxButton('Login',
CController::createUrl('auth/ajaxLogin'),
array(
'type'=>'POST',
'data'=> <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />??,
'dataType'=>'text',
),
array(
'class'=>'btn',
)
);
?>
</form>
I want to send username and password values to controller action via ajax post. How to send form data to controller?
antares
(Antares Mips)
2
<form id="login-form" class="navbar-form pull-right">
<input type="text" class="span2" placeholder="Username">
<input type="password" class="span2" placeholder="Password">
<?php
echo CHtml::ajaxButton('Login',
CController::createUrl('auth/ajaxLogin'),
array(
'type'=>'POST',
'data'=>'js:$("#login-form").serializeArray()',
'dataType'=>'text',
),
array(
'class'=>'btn',
)
);
?>
</form>
Tried but not posting anything…
antares
(Antares Mips)
4
Try this
<form id="login-form" class="navbar-form pull-right">
<input id="login" type="text" class="span2" placeholder="Username">
<input id="pass" type="password" class="span2" placeholder="Password">
<?php
echo CHtml::ajaxButton('Login',
CController::createUrl('auth/ajaxLogin'),
array(
'type'=>'POST',
'data'=>array('login'=>'js:$("#login").val()','pass'=>'js:$("#pass").val()'),
'dataType'=>'text',
),
array(
'class'=>'btn',
)
);
?>
</form>
seenivasan
(Chellamnivas)
5
Dear Friend
Would you please try the following?
1.There is no name attribute for the form fields.Then it is impossible to get serialized.
2.use CHtml::ajaxSubmitButton instead of ajaxButton.
3.Try to include complete function to test the AJAX request in firebug console.(optional)
<form id="login-form" class="navbar-form pull-right">
<input type="text" class="span2" placeholder="Username" name="name">
<input type="password" class="span2" placeholder="Password" name="pass">
<?php
echo CHtml::ajaxSubmitButton('Login',
CController::createUrl('auth/ajaxLogin'),
array(
'type'=>'POST',
'data'=>'js:$("#login-form").serialize()',
'complete'=>'js:function(i,j) {console.log(i);}'
),
array(
'class'=>'btn',
)
);
?>
</form>
Regards.
Thank you seenivasan and antares