pspahn
pspahn

Reputation: 2790

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:

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. I have placed a Mage::log call inside the cartAction(), but it never gets fired.

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).

If I place inside the Ajax call:

console.log(data);

It returns the object with 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.

Any thoughts?

Upvotes: 0

Views: 3722

Answers (2)

pspahn
pspahn

Reputation: 2790

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.

Assigned a different frontname to the admin controller and things are fine.

Upvotes: 1

Fran
Fran

Reputation: 670

First of all, try changing the URL to a standard Magento URL and check if you get a response. At least you would know if the problem is coming from your jQuery request or your controller itself. If you can access your controller action directly in your browser, your module is just fine.

Upvotes: 0

Related Questions