本文介绍了如何在Rails上的ruby中提出ajax请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是刚接触过红宝石的新手.我想知道如何提出ajax请求.我的js代码:

Hello I am new to ruby on rails I have just started to learn. I would like to know how can I make the ajax request.My js code:

$(document).ready(function(){
  $(".form_submit").click(function() {
         var apiid = $('#apiid').val();
         var apikey = $('#apikey').val();
         var email = $('#email').val();
           console.log("apiid  = ",apiid , " apikey = ",apikey , " email = ",email);

  });  
});

现在我想将apiid,apikey和电子邮件发送到我的控制器.

Now I want to send apiid , apikey and email to my controller.

def api 
//here I want apiid, apikey,email from js
end

推荐答案

一旦您通过js将数据通过js发送到服务器,

Once you've sent the data to your server via js with something like

$.post("/your/url",
{
    apiid: "1",
    apikey: "1",
    email: "[email protected]"
});

然后,您可以通过params哈希在控制器中访问以下参数:

Then you can access these parameters in your controller via the params hash:

def api
  params[:apiid]
  params[:apikey]
  params[:email]
end

这篇关于如何在Rails上的ruby中提出ajax请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 04:19