0

I want to call a function in a Helper file, from js file using ajax.

In my config.xml

<global>
    <helpers>
        <customname>
            <class>...

In js file:

jQuery.ajax({

url: "Mage::helper('customname')->getPricesAjaxCall()"
type: "POST",
data: {key: 'value'},
success: function(productId){
    console.log('check 11');
}
});

But I don't know what i should put in the url to correctly call it. Any idea?

  • You should use a phtml file to execute js and please echo helper function output. In js file you cannot use PHP methods – Kumar M Aug 16 '18 at 14:15
0

This is not possible at all and not as per magento standard flow.

All the HTTP/Ajax request that we make in magento are handled by controller actions using the help of Routers.

Its not possible to directly call the Helper function using Ajax.

You can create one Controller Action that will be called using ajax. In Action function you can call helper function to get data and return directly from function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.