本文介绍了ajax调用在rails 3中传递javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script> var depart_date='11 February 2013';
         var depart_date='21 February 2013';


    jQuery.ajax({

data: { depart: depart_date, return_date: return_date},
    type: 'post',
  url: "/payment/create",

});

这是我的 ajax 调用.

This is my ajax call.

在终端中,它的值变为 {"depart"=>"11 February 2013", "return_date"=>"21 February 2013"}

In terminal it's value getting as {"depart"=>"11 February 2013", "return_date"=>"21 February 2013"}

但是在控制器参数[:depart] &params[:return_date] 显示为 nil 值.

But in controller params[:depart] & params[:return_date] shows as nil value.

不知道我哪里做错了..

Don't know where i am doing mistake..

推荐答案

将deep_date改为return_date,并在最后结束脚本为:

Change depart_date to return_date and end the script at the end as:

<script> 

   var depart_date='11 February 2013';
   var return_date='21 February 2013';

        jQuery.ajax({

    data: { depart: depart_date, return_date: return_date},
        type: 'post',
      url: "/payment/create",

    });

    </script>

这篇关于ajax调用在rails 3中传递javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 08:39