Page 1 of 1

Ajax

Posted: Mon Jun 06, 2011 3:39 pm
by jriemer
Anybody have a successful Ajax implementation under z/OS Tomcat? No reason it shouldn't work; however, I'm unable to this point to successfully trigger a Tomcat servlet out of an Ajax Javascript function in a .jsp. Just curious.

Posted: Mon Jun 06, 2011 3:53 pm
by dovetail
It has worked fine for us in the past. Nothing special to do on the server, but it would depend on whether you are using some kind of server-side Ajax framework. Calling Java servlets from client javascript should be no problem.

Ajax

Posted: Mon Jun 06, 2011 5:10 pm
by jriemer
Thanks. Do you use either of the following formats:

1. ajaxRequest.open("POST", "/servlet/servletname", true);
2. ajaxRequest.open("POST", "http://192.168.50.51:8080/servlet/servletname", true);

Neither seems to work for me.

Posted: Mon Jun 06, 2011 5:16 pm
by dovetail
No sorry. I'm not sure what Ajax client side javascript framework you are using. We have used Dojo in the past, but it really shouldn't matter.


Have your written Ajax clients for *any* Tomcat container? Try getting it working first to Tomcat on your desktop. If it works there, it should work when the server is on z/OS - unless your client-side framework requires a server side Java framework that isn't installed on your z/OS instance.

Ajax

Posted: Mon Jun 06, 2011 7:31 pm
by jriemer
Would you be able to provide one of your (simpler) working examples?

Posted: Tue Jun 07, 2011 10:21 am
by dovetail
Sorry, unfortunately it was done as work for hire contract.

Try a simple Dojo example to a local Tomcat running on your desktop first, and then move the app to z/OS.

Posted: Tue Jun 07, 2011 12:23 pm
by dovetail
Sorry, I did find an example, from the "JZOS Cookbook":
http://www.alphaworks.ibm.com/tech/zosj ... k/download

The example web app in this book has a Catalog Search web service that is front-ended with a Flex (Flash) application. But following is an example of a small DoJo client that implements a "live" dataset list picker combo-box thingy.

Code: Select all

<html>
  <head>
    <title>z/OS DSN Picker</title>
      <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dijit/themes/tundra/tundra.css"/>
      <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js" djConfig="parseOnLoad:true, isDebug: true" type="text/javascript"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.4/dijit/dijit.js" djConfig="parseOnLoad:true, isDebug: true" type="text/javascript"></script>
      <script type="text/javascript">
          dojo.require("dijit.form.ComboBox");
          dojo.require("dojo.data.ItemFileReadStore");
      </script>
      <script type="text/javascript">
          function doCbSearch(e) {
            var fkey = dijit.byId("cbDsn").attr('displayedValue') + e.keyChar;
            //console.debug("fkey=" + fkey + " key=" + e.charOrCode + "," + e.keyChar);
            if ((e.keyChar == "") && (e.charOrCode != dojo.keys.BACKSPACE)) {
              return; //Don't query unless a character or backspace has been entered
            }
            dijit.byId("cbDsn").store = new dojo.data.ItemFileReadStore({data: {items: []}});
            var parms = new Object();
            parms.filterkey = (e.charOrCode == dojo.keys.BACKSPACE) ? fkey.substring(0,fkey.length-1) : fkey;
            if (fkey.indexOf(".") == -1) {
              return; //Don't search until a complete HLQ is entered
            }
            parms.filterkey += (fkey[fkey.length-1] == ".") ? "**" : "*.**";
            parms.workarealength = 1024;
    
            dojo.xhrPost({
              url: "api/catalogsearch",
              load: handleResponse,
              error: function(data, ioArgs) {alert("Error: "+data)},
              content: parms,
              handleAs: 'xml'
            });
        }
  
        function handleResponse(data, ioArgs) {
          var entries = new Array();
          for (i=0; i<10; i++) { // take first 10 entries
            var entry = data.getElementsByTagName("entry")[i];
            if (entry == null) {
              break;
            }
            entries[i] =  {'dsn':dojo.attr(entry,"name")};
          }
          dijit.byId("cbDsn").store = new dojo.data.ItemFileReadStore({data: {items: entries}});
        }
      </script>    
  </head>

  <body class="tundra">
  DSN Picker: <input dojoType="dijit.form.ComboBox"
                     id="cbDsn" 
                     searchAttr="dsn" 
                     onKeyPress="doCbSearch" 
                     searchDelay="300"
                     style="width: 44em"
                     highlightMatch="none"
                     autoComplete="false"/>
  </body>
</html>

Ajax

Posted: Tue Jun 07, 2011 9:21 pm
by jriemer
Thanks very much.