title: CakePHP and Ajax request url
body: <p>I am currently using ajax in multiple controllers in my application. I implemented the ajax functionality using the jQuery supported version.</p>
  
  <pre><code>$.ajax({
      url:'getCountries',
      type: "POST",
      dataType: "html",
      data:"data=" + result,
      success: function(data){
                      //magic...
          }
      }
  });
  </code></pre>
  
  <p>As you can see from the code above the url of this request is 'getCountries'.
  This means that if the request is made from</p>
  
  <pre><code>http://localhost/appname/controllername/methodname
  </code></pre>
  
  <p>the request url will be</p>
  
  <pre><code>http://localhost/appname/controllername/getCountries
  </code></pre>
  
  <p>However if the url you are using this script is different than in example above, say   </p>
  
  <pre><code>http://localhost/appname/controllername/methodname/7
  </code></pre>
  
  <p>(like in the edit view), then the request url in the ajax call from those urls will change to</p>
  
  <pre><code>http://localhost/appname/controllername/methodname/getCountries
  </code></pre>
  
  <p>How can I make it so that the request url will be generated automaticly depending on the controller I am currently in?</p>
  
  <p>Please note that the <strong>appname</strong> in the url path is the name of the root folder of the application and it should be also included so that if the files will be transported to a different server/location the javascript link will stay consistent with the root folder also.</p>