简体   繁体   English

Magento-Ajax请求-返回空响应

[英]Magento - Ajax Request - Returns empty response

I am debugging some stuff on a client's site that has a module developed by someone else. 我正在调试客户端站点上的某些东西,该站点上有其他人开发的模块。 It's not working correctly. 它无法正常工作。

I have a simple Ajax call to a controller: 我对控制器有一个简单的Ajax调用:

jQuery.ajax({
    url : "http://www.site.com/quickview/index/cart",
    complete : function(data){
                    // data.responseText is empty here.
                    jQuery('span.topLinks').replaceWith(data.responseText);
                    // This returns the data object with statusText = "error"
                    console.log(data);
    }
})

Which calls a simple action in the controller: 在控制器中调用一个简单的动作:

    public function cartAction()
    {
        // This log call never fires
        Mage::log('foobar',null,'temp.log');
        $this->loadLayout();
        $Top = $this->getLayout()->getBlock('top.links')->toHtml();
        $this->getResponse()->setBody($Top);
    }

The problem is that the Ajax call never makes it to the controller. 问题在于,Ajax调用永远不会到达控制器。 I have placed a Mage::log call inside the cartAction(), but it never gets fired. 我已经在cartAction()内放置了一个Mage :: log调用,但是它从未被触发。

The controller is indeed set up properly, as I can browse directly to cartAction() which will render the block I am attempting to return back to the Ajax call (if I echo it, it's not echoed here). 控制器的设置确实正确,因为我可以直接浏览到cartAction(),它将呈现我尝试返回到Ajax调用的块(如果我回显它,此处将不回显)。

If I place inside the Ajax call: 如果我放在Ajax调用中:

console.log(data);

It returns the object with statusText: "error". 它返回带有statusText:“ error”的对象。

I have tried every permutation of the Ajax URL that I can think of, absolute, relative, with index.php, without index.php, etc. Every time, data.responseText is just an empty string. 我已经尝试过我可以想到的Ajax URL的每个排列,无论是绝对的还是相对的,使用index.php,不使用index.php等。每次,data.responseText都是一个空字符串。

Any thoughts? 有什么想法吗?

This was finally resolved. 终于解决了。 The module also had a controller set up for Adminhtml that used the same frontname so browsing to the controller action directly worked, but when called through the template file via Ajax, it didn't like the http to https switch. 该模块还为Adminhtml设置了一个控制器,该控制器使用相同的前名,因此浏览该控制器操作直接起作用,但是当通过Ajax通过模板文件调用时,它不喜欢将HTTP切换为https。

Assigned a different frontname to the admin controller and things are fine. 为管理控制器分配了不同的姓氏,一切正常。

First of all, try changing the URL to a standard Magento URL and check if you get a response. 首先,尝试将URL更改为标准Magento URL,然后检查是否收到响应。 At least you would know if the problem is coming from your jQuery request or your controller itself. 至少您会知道问题是来自您的jQuery请求还是您的控制器本身。 If you can access your controller action directly in your browser, your module is just fine. 如果您可以直接在浏览器中访问控制器操作,那么您的模块就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM