title: Ajax response from controller
body: <p>My javascript send Ajax request which will invoke a controller function, then the controller function response to the Ajax request. My problem is in the controller response part.</p>
  
  <p>my javascript which send Ajax request to controller:</p>
  
  <pre><code>var xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange=function(){
          if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200){
            //RENDER RESPONSE @cars here
          }
      }
      xmlhttp.open("GET","/cars/reserved_cars/"+customer_id,true);
      xmlhttp.send();
  </code></pre>
  
  <p>So, the above ajax request will invoke my <code>CarsController</code>'s <code>reserved_cars</code> function with <code>customer_id</code> as parameter.</p>
  
  <p>My CarsController:</p>
  
  <pre><code>class CarsController &lt; BaseController
  
  def reserved_cars
      customer_id=params[:customer_id]
  
      @cars = Car.getCars(customer_id)
    end
  ...
  
  
  end
  </code></pre>
  
  <p>My controller get all cars by query Car model with customer_id.</p>
  
  <p>Everything works fine, I just don't know how to return the @cars in controller as response of my ajax request to my javascript (the place in my javascript where I commented "<strong>//RENDER RESPONSE @cars here</strong>")</p>
  
  <p>So, How to get @cars response in my javascript?</p>