2008年11月7日星期五

Re: [fw-mvc] dojo.xhrGet handle as json and controller/action

-- Alessandro Camilli <alex_cam@libero.it> wrote
(on Friday, 07 November 2008, 08:52 AM -0800):
> I'm trying to call a controller/action using xghr.
>
> In my controller/action I have this:
>
> public function getvaluejsonAction(){
> $this->_helper->layout()->disableLayout();
> // Calculate
> $result= $this->calculateAction();
> // result to JSON
> $data = new Zend_Dojo_Data();
> $data->setIdentifier('id');
> $data->addItems(array(
> array('id'=> 'result01', 'value'=>$result)
> ));
> $this->view->datijson = $data;
> }
>
> my view :
> <?php
> $response = Zend_Controller_Front::getInstance()->getResponse();
> $response->setHeader('Content-Type', 'application/x-json');
> echo $this->datijson;
> ?>
>
> and this is my javascript:
> dojo.xhrGet({
> url: "/controller/getvaluejson/",
> load: function(responseObj, ioArgs){
> // like as the example of dojo
> var textBuffer = ["The data returned is:"];
> for(var i = 0; i < responseObj.length; i++){
> alarm(responseObj[i].value);
> textBuffer.push("value:"+responseObj[i].value);
> }
> dojo.byId("divForAjax").innerHTML = textBuffer.join("<br/>");
>
>
>
> //Dojo recommends that you always return(response); to propagate
> //the response to other callback handlers. Otherwise, the error
> //callbacks may be called in the success case.
> return responseObj;
> },
> error: function(responseObj, ioArgs){
> dojo.byId(toId).innerHTML =
> "An error occurred, with response: " + responseObj;
> return responseObj;
> },
> handleAs: "json"
> });
>
> If I call the controller/action directly it works and i can see the file
> with the right tags of json.
> But if I call the controller/action with the function dojo.xhrGet
> the responseObj is empty .

Does FireBug show any data transferred? If so, it's with the xhr handler
you've written.

--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/

没有评论: