I'm loading parts of the page via AJAX whose content includes a customer login link:
Mage::helper('customer')->getLoginUrl()
Clicking the link gets the user to the login page and returns back to the HTTP referrer. Now that's the problem. Since the link is inside the content of an AJAX request the return/referer URL will be http://www.domain.com/ajaxhelper/ajax/custom_ajax/
How do I get the current URL outside the AJAX content? So when I load http://www.domain.com/ajaxhelper/ajax/custom_ajax/
via AJAX from http://www.domain.com/category-a.html
I'd like to return http://www.domain.com/category-a.html
instead of http://www.domain.com/ajaxhelper/ajax/custom_ajax/
Already tried this:
$session = Mage::getSingleton('customer/session');
$session->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl());
Mage::helper('customer')->getLoginUrl();
but as said Mage::helper('core/url')->getCurrentUrl()
returns the url of the AJAX helper instead of the page invoking the AJAX request.
Best Answer
Instead of
you can use
This should give you the referrer of your current page (your current page being
ajaxhelper/ajax/custom_ajax/
). So you should have the URL of the page that did the AJAX call (request). I assume that is what you need.