AJAX requests in Magento

AJAX could be a nice technology that’s wont to improve user expertise and avoid page reloads, however however are you able to use it in your own Magento modules? Let’s explore…

1) You ought to either produce a controller, for example: Namespace/YourModule/controllers/AjaxController.php or produce a brand new action in associate existing controller

2) To make associate action in your controller, like indexAction(), you’d add this code

public function indexAction()
{
    $this->loadLayout();
    $this->renderLayout();
}

3) Then raise yourlayout.xml (example: app/design/frontend/…/…/layout/yourlayout.xml) next code

<yourmodule_ajax_index>
     <block type="yourmodule/yourblock" name="root" template="path/template.phtml" />
</yourmodule_ajax_index>

4) Then you wish to update the layout in config.xml

<layout>
     <updates>
        <yourmodule>
            <file>yourlayout.xml</file>
         </yourmodule>
     </updates>
</layout>

5) once this, the instance of your YourBlock category are going to be obtainable in model.html

6) and at last, you wish to decision your Ajax controller with JavaScript or JQuery, for example:

xmlhttp.open("GET","yourmodule/ajax/index/someval/"+value,true);

or

jQuery.post(“yourmodule/ajax/index”, {someval: value}, function(data){...});

For more Info about Magento Ajax Cart must Visit This Site

Leave a Reply

Your email address will not be published. Required fields are marked *