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 .
Pleas help me. Thanks
--
View this message in context: http://www.nabble.com/dojo.xhrGet-handle-as-json-and-controller-action-tp20384391p20384391.html
Sent from the Zend MVC mailing list archive at Nabble.com.
没有评论:
发表评论