0

Hi i have an Zend Framework apps, the following code are popularAction controller

public function popularAction()
    {
        $type = $this->_getParam('ref',1);
        if($type == 'reviews'){
        $businessReviewMapper = new Application_Model_Mapper_BusinessReviewsMapper();
        $result = $businessReviewMapper->getTotalVote();

        $rotd = $businessReviewMapper->getROTD($result['review_id']);
        $rotd[0]['u_img'] = $this->view->getLoginUserImage($rotd[0]['social_id'],$rotd[0]['login_type'],null,null,square);
        $rotd[0]['rating'] = $this->view->getRatingImg($rotd[0]['rating']);
        $rotd[0]['business_name_url'] = preg_replace("![^a-z0-9]+!i","-", $rotd[0]['business_name']);            
        $this->render('reviews');
        $this->_helper->json($rotd);



        } elseif($type == 'openings') {
            $this->view->text = "New Openings";

        } else {
            $this->_helper->redirector('index', 'index', 'default');
        }

    }

When a user browse to http://localhost/business/popular?ref=reviews the above controller code would render reviews.phtml template. Now inside the template itself there is ajax request for a data as follow:

function getPopular()
{
    var count=1;
    $.ajax({
        url:"<?=$this->baseUrl('business/popular?ref=reviews')?>",
        data:{'count':count},
        dataType:"json"
        type:"POST",
        success:function(data){
            alert('ok')
        }
    });

unfortunately the $this->_helper->json($rotd); doesn't pass data to the reviews.phtml,but display json data which is returned by zend db model, where i might be wrong?Thanks

1 Answer 1

1

If your Goal is to, to send JSON instead of the .phtml File on an Ajax Request, try to implement this:

  if ($this->getRequest()->isXmlHttpRequest()) {
        if ($this->getRequest()-isPost()) {
            $this->_helper->json($rotd);
        }
    }

This part checks if the request is, lets call it: ajax based..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.