Modifying Dojo to use Domino's OutputFormat=JSON
Category source code mods json ReadViewEntries OutputFormat=JSON dojo.io.bind application/x-javascript
Bookmark :
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...
Bookmark :
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>


Comments
I'll dig in a little deeper and find out, but it may be a few days as I'm up to my eyeballs in a project this week.
Posted by Lance At 09:28:17 AM On 06/24/2007 | - Website - |
dojo.xhrGet( {
url: /viewName?readViewEntries&outputformat=JSON,
handleAs: "json",
handle: function(response, ioArgs) {
...
}
});
But what if you want to search a view? Have you found an easy way (or at least a logical way) to get JSON format back when searching a view? The method I am using is extremely convoluted and will be a nightmare to maintain.
Oh, what I wouldn't give for ?searchViewEntries&outputformat=JSON!
Posted by Michelle Snow At 02:49:25 AM On 07/15/2007 | - Website - |
"-) stw
Posted by Stephan H. Wissel At 12:11:23 AM On 06/24/2007 | - Website - |