title: Render in HTML result of ajax call with Ruby / Sinatra
body: <p>I have a jquery which uses parameters to query the Plivo api. </p>
  
  <pre><code>$(".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'
          }
        });
  });
  </code></pre>
  
  <p>The ruby code block receives the parameters and queries through the api</p>
  
  <pre><code>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' =&gt; country_iso, 'region' =&gt; region, 'prefix' =&gt; prefix, 'limit' =&gt; 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
  </code></pre>
  
  <p>The parameters are passed and the terminal console shows a successful result:</p>
  
  <pre><code>{"country_iso"=&gt;"US", "region"=&gt;"NY", "prefix"=&gt;"646", "limit"=&gt;1}
  57  # = puts obj["objects"][0]["stock"]
  New York, UNITED STATES # = puts obj["objects"][0]["region"]
  </code></pre>
  
  <p>My question is this: how can I "echo" the ressults on my local.erb page? Local.erb below:</p>
  
  <pre><code>&lt;h2&gt;Your search returned the following result&lt;/h2&gt;
          &lt;ul&gt;
            &lt;li&gt;&lt;span class="fixed"&gt;Stock:&lt;/span&gt;&lt;span class="fixed"&gt;&lt;%= @region %&gt;&lt;/span&gt;&lt;/li&gt;
            &lt;li&gt;&lt;%= @region %&gt;&lt;/li&gt;
            &lt;li&gt;&lt;%= @prefix %&gt;&lt;/li&gt;
            &lt;li&gt;&lt;%= @voice_rate %&gt;&lt;/li&gt;
            &lt;li&gt;&lt;input type="submit" class="buynumber" value="Buy this number" /&gt;&lt;/li&gt;
            &lt;/ul&gt;
  </code></pre>
  
  <p>The results are only printed in the terminal with puts .. and nothing appears on the local.erb page when the jquery redirects the user to local.erb. </p>
  
  <p>Thank you for considering this!</p>