我有一个 jquery,它使用参数来查询 Plivo api。
$(".localsearch").click(function() {
var country_iso = $("#local").val();
var region = $("#region").val();
var prefix = $("#prefix").val();
$.ajax({
type: "GET",
url: "/local/data",
data: { 'country_iso' : country_iso, 'region' : region, 'prefix' : prefix },
success: function(data){
window.location.href = '/local'
}
});
});
ruby代码块通过api接收参数和查询
get '/local/data' do
country_iso = params[:country_iso]
region = params[:region]
prefix = params[:prefix]
p = RestAPI.new(AUTH_ID, AUTH_TOKEN)
params = {'country_iso' => country_iso, 'region' => region, 'prefix' => prefix, 'limit' => 1}
warn params.inspect
response = p.get_number_group(params)
obj = response.last
puts obj["objects"][0]["stock"]
puts obj["objects"][0]["region"]
@stock = obj["objects"][0]["stock"]
@region = obj["objects"][0]["region"]
@prefix = obj["objects"][0]["prefix"]
@voice_rate = obj["objects"][0]["voice_rate"]
erb :local
end
参数传递,终端控制台显示成功结果:
{"country_iso"=>"US", "region"=>"NY", "prefix"=>"646", "limit"=>1}
57 # = puts obj["objects"][0]["stock"]
New York, UNITED STATES # = puts obj["objects"][0]["region"]
我的问题是:如何在我的 local.erb 页面上“回显”结果?Local.erb 如下:
<h2>Your search returned the following result</h2>
<ul>
<li><span class="fixed">Stock:</span><span class="fixed"><%= @region %></span></li>
<li><%= @region %></li>
<li><%= @prefix %></li>
<li><%= @voice_rate %></li>
<li><input type="submit" class="buynumber" value="Buy this number" /></li>
</ul>
结果仅使用 puts .. 打印在终端中,当 jquery 将用户重定向到 local.erb 时,local.erb 页面上没有任何内容。
感谢您考虑这一点!