1

我将在 Magento 块中发出一个 AJAX 请求,该请求在我自己的模块控制器中调用一个动作。但是这个请求的响应是302,如果我没有登录,会在管理员登录页面重定向。这个请求在前面,不需要管理员登录。

我的 JavaScript 代码:

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']);

我的控制器代码:

class ColisWeb_DisponibilityShippingIcon_DisponibilityController extends Mage_Adminhtml_Controller_Action
{

public function setcustomeraddressinsessionAction() {
    $params = $this->getRequest()->getParams();
    Mage::log("ColisWeb - Addresse du visiteur non poussé en 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));   
}

}
?>

我的 Magento 版本是 1.4.2

我希望有人能帮助我。

谢谢你的帮助!

4

1 回答 1

1

Your controller extends Mage_Adminhtml_Controller_Action - it should be Mage_Core_Controller_Front_Action instead.

于 2013-01-15T13:27:44.790 回答