2008年11月11日星期二

Re: [fw-mvc] Zend_Dojo AJAX Requests

this seems to have been fixed in 1.7.0. What worked for me was to require all
"possibly needed" dojo/dijit modules in Bootstrap. This means all modules
must be required when the layout script is rendered (before the actual
"content" for filling a dijit.dialog element is retrieved via Ajax call
which is typically the case when invoking thickboxes):

Zend_Dojo::enableView($view);
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
$view->dojo()->setCdnBase(Zend_Dojo::CDN_BASE_GOOGLE)
->setCdnVersion("1.2")
->setCdnDojoPath(Zend_Dojo::CDN_DOJO_PATH_GOOGLE)
->requireModule("dojo.parser")
->requireModule("dijit.form.Button")
->requireModule("dijit.Dialog")
->requireModule("dijit.form.Textarea")
->requireModule("dijit.form.ValidationTextBox")
->requireModule("dijit.form.ComboBox")
->requireModule("dijit.form.DateTextBox")
->setDjConfigOption("parseOnLoad", true)
->addStyleSheetModule("dijit.themes.tundra");
$view->dojo()->disable();

I only found out after using the browser's JS console where an error was
thrown I could not explain:

Error parsing in _ContentSetter#Setter_DIV_0

Turns out, this is thrown by Dojo's parser if one of the dijit elements'
module needed to parse the element was not made available via
requireModule("dijit.[module]") before using it:

In a view script:

<script type="text/javascript">
function openThickbox(){
dojo.xhrGet({
// call module, controller, action and pass parameter format=json
url: "/module/controller/action/format/json",
load: thickboxCallback,
error: thickboxError
});
}

function thickboxCallback(data, ioArgs){
dijit.byId("thickbox").setContent(data);
dijit.byId("thickbox").show();
}

function thickboxError(data, ioArgs) {
console.debug("error ...");
}
</script>

< a href="#" onclick="openThickbox()">Open thickbox< /a>

<div dojoType="dijit.Dialog" id="thickbox" title="Thickbox"></div>


Matthew Weier O'Phinney-3 wrote:
>
> --
>
> The problem I alluded to is that Javascript will not execute <script>
> tags returned by XHR requests. You can certainly write a handler for
> JSON responses, however, that could do as you suggest; the difficulty
> there would be if you want to mix HTML and JS. Additionally, you may
> have some issues with encoding JS to insert into JSON until we get JS
> expression support added to Zend_Json (this proposal is up for review
> now, however, and may be included for 1.7.0).
>

--
View this message in context: http://www.nabble.com/Zend_Dojo-AJAX-Requests-tp20047453p20454541.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: