[英]Ruby on rails: How to send an AJAX request to rails controller from login popup along with user given credentials
Also, how to use the values entered in the popup, in the javascript function: login_request()
which is being called on click, which will send the AJAX request eventually. 另外,如何使用在javascript函数中输入的值login_request()
在点击时被调用的javascript函数: login_request()
,该函数最终将发送AJAX请求。
Note: The code snippet includes all the fields enclosed in the popup. 注意:该代码段包含弹出窗口中包含的所有字段。
<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>
Thanks. 谢谢。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.