title: Cakephp ajax function not working
body: <p>I am new to <code>cakephp</code> and trying to implement ajax in it. my controller <code>photographers</code> function <code>api_search</code> is:</p>
  
  <p><code>/*resides in photographers_controller.php*/</code></p>
  
  <pre><code>function api_search() {
          return 'Demo';
      }
  </code></pre>
  
  <p>And the <code>search.ctp</code> is :</p>
  
  <pre><code>&lt;script&gt;
  
  $(document).ready(function() {
      get_search_results();
  });
  
  function get_search_results() {
      //get the selected location_id
  
      var gal_location_id = 0;
  
      //get the selected package
      var starting_package_wedding = 1;
  
      var data = "gal_location_id="+gal_location_id+"&amp;starting_package_wedding="+starting_package_wedding;
  
      //var url_to_call = '&lt;?php echo $html-&gt;url(array("controller"=&gt;"gal_providers","action"=&gt;"api_search")); ?&gt;';
      var url_to_call = "http://localhost/myshaadi/photographers/api_search";
  
      $.ajax({
          type: "GET",
          url: url_to_call,
          // async: false,
          dataType: "json",
          data: data,
          error:function(resp){
  
          },
          success: function(resp){
              alert('Upto here');
              //render_search_result(resp);
          }
      });
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>I was expecting an alert of <code>Upto here</code>, but it is not alerting anything after page loads ! Whats wrong?</p>