1

I try to call my controller from a phtml template file using ajax, and I don't know what's wrong.

It looks like I got only some routing issues :

in my config.xml :

<routers>
    <Samplefolder>
        <use>admin</use>
        <args>
            <module>MyModule_Samplefolder</module>
            <frontName>SampleFolder</frontName>
        </args>
    </Samplefolder>
</routers>

Block/Adminhtml/OnePageFolder.php:

public function getAddCardUrl() {
    $url = Mage::helper('adminhtml')->getUrl('SampleFolder/OnePageFolder/AddCard');
    //$url = $this->getUrl('*/*/AddCard');
    return $url;
}

app/design/adminhtml/default/default/template/Samplefolder/OnePageFolder.phtml:

var url = '<?php echo $this->getAddCardUrl(); ?>';
// this url is called from http://mywebsite.com/index.php/admin/SampleFolder/OnePageFolder/index/key/cd0efd9a23e6bee7462e0fed5db6ac67/ and is looking like http://mywebsite.com/index.php/admin/SampleFolder/OnePageFolder/AddCard/key/17cf35ef0cae06459e7acf46b7e2e6d5/ which looks good

//then I call my controller with AJAX : 

ajaxCall(url,5478,1234 );

function ajaxCall(url,customer_id,club_id)
{
    jQuery.ajax({
        url: url,
        type: 'POST',
        data: {customer_id:customer_id, club_id:club_id},
        dataType: 'json',
        success: function(json) {
            if(json.response == 'ok') {
                alert('good');
            } else {
                alert('Erreur : '+ json.message);
            }
        }
    });
}

And Finally the controller that I can't reach

/controllers/OnePageFolderController.php:

/**
 * Add club card
 *
 */
public function AddCardAction()
{

    var_dump('this code is not reached');
    die;
}

I got the error router match 100 iteration in my ajax callback, but I don't know what is badly configured here. I use a controller already defined and working.

for example I have a non ajax button which works with a call like: Mage::helper('adminhtml')->getUrl('SampleFolder/OnePageFolder/DownloadList') with its function just above mine in the controller.

Edit : even when I call this method directly from url, I got the error, so it means that it is not an ajax issue but a backend problem with routing behaviour

Nicolas D
  • 1,182
  • 18
  • 40

2 Answers2

0

Instead of: ajaxCall(addCardUrl,5478,1234 );

Try: ajaxCall(url,5478,1234 );

Gerard de Visser
  • 7,590
  • 9
  • 50
  • 58
  • sorry this is just a typo rewriting the code to sum up, but as I said the ajax call is well made on firebug with a good url, I edit, ty – Nicolas D Mar 07 '16 at 15:53
  • any idea of the problem? It seems to be on back side and not front as my ajax call looks exactly as I expected. I don't know why I am not reaching my controller function. – Nicolas D Mar 07 '16 at 15:57
  • Maybe you can debug 100 iteration error with the answers on this question: http://stackoverflow.com/questions/6262129/magento-front-controller-reached-100-router-match-iterations-error ? – Gerard de Visser Mar 07 '16 at 16:15
  • when I do that I got 100 iterations of : 2016-03-07T16:20:58+00:00 DEBUG (7): - Iteration 100 2016-03-07T16:20:58+00:00 DEBUG (7): Request: [path_info=/SampleFolder/OnePageFolder/AddCard/key/17cf35ef0cae06459e7acf46b7e2e6d5/][module=admin][action=noRoute][controller=index][controller_module=][route=SampleFolder] 2016-03-07T16:20:58+00:00 DEBUG (7): Matched by "default" router, class Mage_Core_Controller_Varien_Router_Default – Nicolas D Mar 07 '16 at 16:22
0

I finally found my solution, it was an override issue. I was in a local controller, but magento was pointing on the one in community.

Nicolas D
  • 1,182
  • 18
  • 40