Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在ruby on rails中使用jquery getJSON获取数据_Javascript_Jquery_Ruby On Rails_Ruby On Rails 3.2_Getjson - Fatal编程技术网

Javascript 在ruby on rails中使用jquery getJSON获取数据

Javascript 在ruby on rails中使用jquery getJSON获取数据,javascript,jquery,ruby-on-rails,ruby-on-rails-3.2,getjson,Javascript,Jquery,Ruby On Rails,Ruby On Rails 3.2,Getjson,我试图通过getJSON方法获取账单金额。虽然我得到了金额,但我无法发布。代码如下 在形式上 <div class="bill"> <%= f.collection_select :customer_bill_id, CustomerBill.all,:id,:id, {:prompt => "Select Customer bill"} %></div><br /> <div class= "due"><%= f.inp

我试图通过getJSON方法获取账单金额。虽然我得到了金额,但我无法发布。代码如下

在形式上

<div class="bill">
<%= f.collection_select :customer_bill_id, CustomerBill.all,:id,:id, {:prompt => "Select Customer bill"} %></div><br />

<div class= "due"><%= f.input :bill_due_amount, :label => "Bill Due Amt.", :input_html => { :size => 20} %> </div><br />
在控制器里我有

def get_due_amount
    @due_amount = CustomerBill.find_all_by_id(params[:customer_bill_id]).map{|bill| [bill.bill_due_amount]}if params[:customer_bill_id]
    respond_to do |format|
      format.json { render json: @due_amount }
    end
  end
如果我发出
警报(res)我确实得到了金额值,但当我得到时

getAmount = jQuery('.due').val(res);
        alert(getAmount);
我得到
[object object]

有什么问题吗?为什么该值没有出现在表单中?寻求指导。提前感谢。

您使用了jQuery('.due'),但这是一个div元素。Fou需要按照以下方式设置表单输入值

jQuery('.due input').val(res); 
它将amout设置为文本框值

jQuery('.due input').val(res);