When i am making ajax call i am getting error ‘An element with a “sellerpage” ID already exists’.
Here is my controller.
namespace VendorModuleControllerSellers;
class Index extends MagentoFrameworkAppActionAction
{
protected $_pageFactory;
protected $resultJsonFactory;
protected $_coreRegistry;
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $pageFactory,
MagentoFrameworkRegistry $coreRegistry,
MagentoFrameworkControllerResultJsonFactory $resultJsonFactory
)
{
$this->_pageFactory = $pageFactory;
$this->_coreRegistry = $coreRegistry;
$this->resultJsonFactory = $resultJsonFactory;
return parent::__construct($context);
}
public function execute()
{
$ajax = $this->getRequest()->getParam('isAjax');
$id=$this->getRequest()->getParam('id');
if($ajax == 'true')
{
try
{
if($id)
{
$this->_coreRegistry->register('id', $id);
}
$resultPage = $this->_pageFactory->create();
$result = $this->resultJsonFactory->create();
$block = $resultPage->getLayout()
->createBlock('VendorModuleBlockSellers')
->setTemplate('Vendor_Module::sellers.phtml')
->toHtml();
$response['block']=$block;
$result->setData(['output' => $response]);
return $result;
} catch (Exception $e) {
$response = $e->getMessage();
return $this->getResponse()->setBody($response);
}
}
else
{
return $this->_pageFactory->create();
}
}
}
here is my block
namespace VendorModuleBlock;
class Sellers extends MagentoFrameworkViewElementTemplate
{
protected $_sellerCollection;
protected $_storeManager;
protected $_sellerList;
protected $_coreRegistry;
public function __construct(VendorModuleBlockSellers $_sellerList,VendorModuleModelResourceModelSellersCollectionFactory $sellerCollection,VendorModuleModelStatesFactory $states,MagentoStoreModelStoreManagerInterface $storeManager,MagentoFrameworkAppRequestHttp $request,MagentoFrameworkRegistry $coreRegistry,MagentoFrameworkViewElementTemplateContext $context,array $data = [])
{
parent::__construct($context, $data);
$this->_sellerList = $_sellerList;
$this->_sellerCollection = $sellerCollection;
$this->_storeManager = $storeManager;
$this->request = $request;
$this->_coreRegistry = $coreRegistry;
}
protected function _prepareLayout()
{
parent::_prepareLayout();
if($this->getRegSellerCollection())
{
$pager = $this->getLayout()->createBlock('MagentoThemeBlockHtmlPager','sellerpage')->setAvailableLimit(array(5=>5,10=>10,15=>15,20=>20));
$pager->setShowPerPage(true);
$pager->setCollection($this->getRegSellerCollection());
$this->setChild('pager', $pager);
$this->getRegSellerCollection()->load();
}
return $this;
}
public function getRegSellerCollection()
{
$page = ($this->getRequest()->getParam('p')) ? $this->getRequest()->getParam('p') : 1;
$pageSize = 5;
if ($this->_coreRegistry->registry('id')) {
$id = $this->_coreRegistry->registry('id');
$collection = $this->_sellerCollection->create();
$collection->addFieldToFilter('sellers',array('like'=>'%'.$id.'%'));
$collection->setPageSize($pageSize);
$collection->setCurPage($page);
}
else
{
$collection = $this->_sellerList->create();
$collection->setPageSize($pageSize);
$collection->setCurPage($page);
}
return $collection;
}
public function getPagerHtml()
{
return $this->getChildHtml('pager');
}
}
When i am loading page it’s working fine. but whenever i am making ajax call it’s throwing error ‘An element with a “sellerpage” ID already exists’.