« Welcome to Dojomino | Main| xhrPost to Domino »

Modifying Dojo to use Domino's OutputFormat=JSON

Category      
Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 

With Domino 7.0.2 you can get a JSON formatted response from Domino server's View URL commands, things like ?ReadDesign and ?ReadViewEntries. By adding the argument &OutputFormat=JSON the Domino server will produce JSON instead of XML. The Content-Type of this output is application/x-javascript. When integrating with Dojo 0.4.2, this is an issue as the standard AJAX type call from Dojo, dojo.io.bind(), recognizes many different Content-Types, but application/x-javascript isn't one of them.

To resolve, I chased down the 2 lines of code in the default dojo.js file and modified them to add that mimetype. It is available here. The 2 lines are line 2695 and 2791. More...

Why mod dojo.js?

You don't have to by any means. But I wanted to work with Domino's JSON output and figure out how to get Dojo to accept it. Here's some example code that will get view entries back as json:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html>
<head>
<script type="text/javascript" src="dojo.js"> </script>
<script type="text/javascript">
function initView() {
    var kw = {
        url : '/view2007/baseball.nsf/Players?ReadViewEntries&OutputFormat=JSON',
         mimetype: 'application/x-javascript',
        method: 'GET',
         load: function(type, data, evt) {
            var myData = data;
            var o = dojo.byId("output");
            o.innerHTML = data.@toplevelentries + " entries in the Players view";
        }
    };
    dojo.io.bind(kw);
}
dojo.addOnLoad(initView);
</script>
</head>
<body>
<div id="output"></div>
<div id="dojoDebugOutput"></div>
</body>
</html>

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)