title: Magento - constructing controller URL in JavaScript
body: <p>I have a custom module. In the custom module's layout file, it references a layout from the customer module:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;layout version="0.1.0"&gt;
      &lt;customer_account_login&gt;
          &lt;reference name="before_body_end"&gt;
              &lt;block type="mymodule/myblock" name="mymodule_myblock" as="mymodule_myblock" /&gt;
          &lt;/reference&gt;
      &lt;/customer_account_login&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>My block class's _toHtml() method returns some JavaScript. That JavaScript makes an async XMLHttpRequest to a controller in my module. It works fine, but I have one issue that I am not sure how to resolve...</p>
  
  <p>On my first attempt, when the XMLHttpRequest in my JavaScript was POSTed to /mymodule/mycontroller/myaction, it did not work (I got a 404). The page that the request was made from was <a href="http://myplace.com/index.php/customer/account/login/" rel="nofollow">http://myplace.com/index.php/customer/account/login/</a>, so I prepended "/index.php" to the URL to which the POST request was made, so that it was now /index.php/mymodule/mycontroller/myaction. That worked. But it is not generic.</p>
  
  <p>My question is not how I get rid of index.php from my URLs (I've seen some posts about that on this site), but rather if my extension is installed on several Magento installations, I'll need to know how to construct the URL in any particular case.</p>
  
  <p>The page will not always be customer/account/login, so I can't just look at window.location.pathname and parse the result.</p>
  
  <p>Any ideas?</p>
  
  <p>Thank you.</p>