此外,如何使用在弹出窗口中输入的值,在 javascript 函数中:login_request()
,它在点击时被调用,最终将发送 AJAX 请求。
注意:代码片段包括弹出窗口中包含的所有字段。
<input class="csrf-token" type="hidden" name="authenticity_token" value="">
<div class="form-row clearfix">
<label class="lbl-fld">Email ID</label>
<input type="email" name="user[email]" ng-model="loginForm.email" placeholder="me@example.com" ng-required="true"/>
<!--<span class="valid-chk">-->
<!--<i ng-class="{'false':'icon-close', 'true': 'icon-correct'}[form['user[email]'].$valid]"></i>-->
<!--</span>-->
</div>
<div class="form-row clearfix">
<label class="lbl-fld">PASSWORD</label>
<input type="password" name="user[password]" placeholder="password" ng-required="true"/>
<!--<span class="valid-chk">-->
<!--<i ng-class="{'false':'icon-close', 'true': 'icon-correct'}[form['user[password]'].$valid]"></i>-->
<!--</span>-->
</div>
<div class="btn-container clearfix">
<div class="btn-wrap">
<input type="submit" name="commit" value="LOGIN" ng-click="login_request()" />
</div>
<div class="loader-wrapper" ng-show="loading" style="bottom: 25px;left: -53px;position: absolute;width: 25px;">
<img class="loader-img-common" src="<%= asset_path('loader.gif') %>" style="max-width: 100%;" />
</div>
</div>
谢谢。
最佳答案
function login_request(data_to_send)
{
$.ajax({
type: 'post',
url: 'controller/action',
data: { key: "value" key_1: "value_1" },
success: function(data) {
// paste your code here after success
}
});
}
#in your config/route.rb
match 'controller/action', :to => 'controller#action' ,:via => [:get,:post] # i'm using get as well as post also.
#hope that help you. if you face any problem please let me know
关于javascript - rails 上的 ruby : How to send an AJAX request to rails controller from login popup along with user given credentials,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34606464/