Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-02-2008, 04:30 PM
Junior Member
 
Join Date: May 2008
Posts: 1
Default Problem with ajax(json) - empty response

I have following code in my bootstrap file:
PHP Code:
...
/**
 * Setup controller
 */
$controller Zend_Controller_Front::getInstance();
$controller->setControllerDirectory('../application/default/controllers');
$controller->throwExceptions(true); // should be turned on in development time

/**
 * Set Zend Layout
 */
Zend_Layout::startMvc();
//Zend_Layout::getMvcInstance()->setViewSuffix('tpl');

/**
 * Check ajax requests
 */
Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_AjaxContext());
... 
I've made AjaxController:

PHP Code:
<?php
/**
 * AjaxController
 * 
 * @author
 * @version 
 */
require_once 'Zend/Controller/Action.php';
require_once 
'Zend/Json.php';

class 
AjaxController extends Zend_Controller_Action
{
    public 
$ajaxable = array('convert'=>array('json'));
    
    function 
init()
    {
          
$this->_helper->viewRenderer->setNoRender();
          
//$this->_helper->ajaxContext->initContext('json'); 
    
}
    
    public function 
preDispatch()
    {
         
$this->_helper->viewRenderer->setNoRender();
        
$this->_request->setParam('format''json');
        
$this->_helper->ajaxContext()->initContext();
    }

    
/**
     * The default action - show the home page
     */
    
public function indexAction ()
    {
    }
    
    public function 
convertAction()
    {
        
//file_put_contents('C:/sasa.txt', $this->getRequest('text'));
        
file_put_contents('C:/sasa.txt'var_export($this->getRequest('text'), true));
        
//var_dump($_POST);
    
        
$jsonData Zend_Json::encode($_POST);
        echo 
$jsonData;        
        
//$this->response->appendBody($jsonData);
        //$this->getResponse()->setBody($jsonData);
    
}
}
And whatever I response in convertAction, I get : '[]' - empty brackets in my response, and that makes invalid json object on the client! So I can't eval it.

Also have a problem that when I have ajax action, I cannot get :

PHP Code:
$this->getRequest('text'); 
Even if $_POST['text'] is properly set.

What is the problem?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:08 AM.