I am facing an issue with my AJAX request in Magento block which triggers an action in my module controller. The problem is that the response of this request is a 302 status code, leading to a redirect to the admin sign-in page if I am not logged in. However, this request should be accessible from the front-end and does not require admin authentication.
Here is my JavaScript code:
var xmlhttp;
if(typeof XMLHttpRequest !== 'undefined') xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "http://mac-4.local:8888/magento_sample_1.4.2/index.php/disponibilityshippingicon/disponibility/setcustomeraddressinsession/", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send('city=' + jsonAddress['city'] + '&cp=' + jsonAddress['cp'] + '&country=' + jsonAddress['country']);
And here is my controller code:
class ColisWeb_DisponibilityShippingIcon_DisponibilityController extends Mage_Adminhtml_Controller_Action
{
public function setcustomeraddressinsessionAction() {
$params = $this->getRequest()->getParams();
Mage::log("ColisWeb - Visitor's address not pushed into session : " . $params['city'] . $params['cp'] . $params['country'], Zend_log::INFO);
if (isset($params['city'], $params['cp'], $params['country'])) {
//new Mage_Customer_Model_Address();
$address = Mage::getModel('customer/address');
$address->setCity($params['city']);
$address->setPostCode($params['cp']);
$session = Mage::getSingleton('core/session');
$session->setData('addressColisweb', $address);
$session->setData('cityAddressColisweb', $params['city']);
$session->setData('postCodeAddressColisweb', $params['cp']);
$session->setData('contryAddressColisweb', $params['country']);
}
else {
}
$this->getResponse()->setHeader('Content-type', 'application/json', true) ;
$result = array( 'status' => '200');
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
?>
This pertains to my version of Magento 1.4.2
Your assistance on this matter would be greatly appreciated.
Thank you for your help!