Hi there to all first post, so go easy on the newbie :-)

I've done PHP for several years, and a bit of AJAX, though a while ago
(cpaint anyone?). New to ZF and Dojo. Trying to get a simple xhrPost to work
right and having issues - not sure if it's ZF or Dojo. 

When my ajax cal lis returned - it adds in the entire layout to the response
div instead of just the partial. Is there a way to just render the partial
and have that inserted? I think this is something I need to do in the
controller so that the entire layout is not rendered - just the view.
Perhaps something with named segments?

MVC Application

Controller:
        public function editajaxAction(){
                switch($this->_getParam('formType')){
                        case "addPlantUse":
                                //Insert use data for the plant into the rel 
table
                                Zend_Loader::loadClass('PlantsPlantUses');
                                $useObject = new PlantsPlantUses();
                                $data = array(
                                        "plantID" => 
$this->_getParam('plantID'),
                                        "useAbbreviation" => 
$this->_getParam('plantUse'));
                                $useObject->insert($data);
                                
                                //Get new list of uses for this plant
                                $plant = new Plants();
                                $plantRowSet = 
$plant->find($this->_getParam('plantID'));
                                $plantRow = $plantRowSet->current();
                                $plantUses = 
$plantRow->findManyToManyRowset('PlantUses',
'PlantsPlantUses');
                                
                                //Add data to the view
                                $this->view->useList =
$plantUses->toArray();
                                $this->render('editPlantUsePartial'); break;
                }
        }

layout.phtml
[SNIP]
<? if ($this->dojo()->isEnabled()){
        $this->dojo()->setLocalPath(BASEURL.'js/dojo/dojo.js')
                                 ->addStyleSheetModule('dijit.themes.tundra');
        echo $this->dojo();
   }
?>
</head>
<body>
<?= $this->partial('header.phtml') ?>
<div id="resultcell">
<?= $this->layout()->content ?>
</div>
</div>
<?= $this->partial('footer.phtml') ?>
</body>
</html>

edit.phtml
<? $this->dojo()->javascriptCaptureStart() ?>
var ajaxAdd = function(divID, formName) {
        var kw = {
                url: "<?=BASEURL."plants/index/ediajax"?>",
                handleAs:"text",
                load: function(response){
                                dojo.byId(divID).innerHTML = response;
                },
                error: function(data){
                                alert("An error occurred: " + data);
                },
                timeout: 2000,
                form: formName
        };
        dojo.xhrPost(kw);  //Servlet get argement with doPost
}
        <? $this->dojo()->javascriptCaptureEnd() ?> 
....
(I'm being generic so I can use this for multiple forms on the page)
....
          <div id="plantUses"> //The partial is displayed properly on load, but
whole layout displayed after AJAX call
                <?=$this->partial('index/edit-plant-use-partial.phtml', 
array("useList"
=>$this->info["uses"]))?>
          </div>

edit-plant-use-partial.phtml
<ul style="margin-top: 0px">
<? foreach ($this->useList as $use) {
        echo "<li>
\"".BASEURL."plants/use/detail/useAbbreviation/".$use["useAbbreviation"]."\"
".$use["useAbbreviation"]." - ".$use["useName"]." </li>";
}
?></ul>

-Mark G.
-- 
View this message in context: 
http://www.nabble.com/ZF-1.6-%2B-Dojo-xhrPost-tp19620432p19620432.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to