javascript - How to submit a form using Ajax from a mobile application -


i need submit form below (components/com_users/views/login/tmpl/default_login.php. ) using ajax.

<form action="<?php echo jroute::_('index.php?option=com_users&task=user.login'); ?>" method="post">      <fieldset>         <?php foreach ($this->form->getfieldset('credentials') $field): ?>             <?php if (!$field->hidden): ?>                 <div class="login-fields"><?php echo $field->label; ?>                 <?php echo $field->input; ?></div>             <?php endif; ?>         <?php endforeach; ?>                      ...... </form> 

my ajax request come external mobile app (on click, run javascript ajax submit form).

is possible? if yes, parameters should pass ajax request (based on example here : "form submit ajax passing form data php without page refresh" need pass url, data , success).

if possible, i'm able pass username , password (which form fetch them fieldset), can provide them in plain text (no security concerns that).

use serialize: documentation

in case add id or name form or if form in page can just:

$('selectorofbuttonthattriggers').click(function(){     $.ajax({             type: 'post',             url: $('form').attr('action'),             data: $('form').serialize(),             success: function(data){                    alert(data);             }     }); }); 

all form field fetch , on server side post keys fields input names.

to add more data programatically can use:

data: $('form').serialize() + "&more1=" + more1value 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -