donate Buy us a cup of coffee
Our service is free. But your donation can help us keep running. To rent a server and domain, to buy us a cup of coffee, to reduce our activity in paid stuff and make this service better. You can send us a donation to BCA Bank, 008 090 8440 in the name of Abdul Malik Ikhsan with Swifcode CENAIDJA. Please confirm to samsonasik@gmail.com after that ;).
download Download module      



Ajax example with Zend Framework 2

This example contains about How to use Ajax in Zend framework 2 codes, The most important parts of using Ajax in Zend Framework are these things:

1. ViewJsonStrategy to your config.
        
            
                'view_manager' => [
                    'strategies' => [
                        'ViewJsonStrategy',
                    ],
                    'template_path_stack' => [
                        __DIR__ . '/../view',
                    ],
                ],
                    
    
2. acceptableviewmodelselector controller plugin.
        
            $acceptCriteria = [
                'Zend\View\Model\JsonModel' => ['application/json'],
                'Zend\View\Model\ViewModel' => ['text/html'],
            ];
            $viewModel = $this->acceptableviewmodelselector($acceptCriteria);
        
    
3. JsonModel.
        
            
                if (!$viewModel instanceof JsonModel && $request->isXmlHttpRequest()) {
                    $viewModel = new JsonModel();
                }
                    
    

By the way, you can find other examples using Zend Framework 2 in our home page :)

 

Ajax Zend framework 2 example ViewJsonStrategy Zend Framework 2 example acceptableviewmodelselector plugin Zend Framework 2 example JsonModel Zend Framework 2 example