Magento Themes and Magento Extensions

Magento – handle ajax call

Share

Creating an ajax request call in magento is quite easy.

All the requests are handled by the controllers in Magento. So Inside the request controllers we need to create a block programmatically which will return a view html output.

Magento uses “block” concept to handle the html output. Blocks are special classes that handles the view section in magento.

Now create the ajax function and send your ajax request to this controller action.

This code will create and render a block in the controller and will return the html output.

public function ajaxRequestAction(){
	$block = $this->getLayout(); // load the layout
	$block->createBlock("modulename/blockname"); // e.g. ("core/template")
	$block->setTemplate("Your template path/templatename.phtml");
	echo $block->renderView(); // now this will show the output of the block
}

Comments are closed.