× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Looks great Shane.  Remember that you don't need to use RPG to use AJAX.  You 
can retrieve data straight from your IFS.  In my case, it is recurring text to 
be displayed on a web page ticker.

________________________________

From: web400-bounces@xxxxxxxxxxxx on behalf of Shane_Cessna@xxxxxxx
Sent: Thu 9/21/2006 9:58 AM
To: Web Enabling the AS400 / iSeries
Subject: Re: [WEB400] AJAX



Wow...thanks to all who have given feedback and suggestions on this...I
really appreciate it...

Here's how I got a small amount AJAX to work using CGIDEV2...

HTML file ajaxtest.html
-----------------------
<html>
<head>
<script src="firstnameajax.js"></script>
</head>

<body>

<form>
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>

<p>Suggestions: <span id="txtHint"></span></p>

</body>
</html>


Javascript file firstnameajax.js
--------------------------------
var xmlHttp

function showHint(str) {
  if (str.length==0) {
    document.getElementById("txtHint").innerHTML="";
    return;
  }
  xmlHttp = GetXmlHttpObject();
  if (xmlHttp==null) {
    alert ("Browser does not support HTTP Request");
    return;
  }
  var url = "/cgi-bin/ajxfirstnm";
  url = url + "?q=" + str;
  url = url + "&sid=" + Math.random();
  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function stateChanged() {
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
    document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
  }
}

function GetXmlHttpObject() {
  var objXMLHttp = null;
  if (window.XMLHttpRequest) {
    objXMLHttp = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  return objXMLHttp;
}

SQLRPGLE Program AJXFIRSTNM
---------------------------
     h bnddir('CGIBIN/CGIDEV2BND') datfmt(*USA) timfmt(*HMS)
     h dftactgrp(*no) actgrp('AJAX') bnddir('TEMPLATE2':'QC2LE')
     
//--------------------------------------------------------------------
      // Prototypes
     
//--------------------------------------------------------------------
      /copy cgidev2/qrpglesrc,prototypeb
      /copy cgidev2/qrpglesrc,variables3
      /copy cgidev2/qrpglesrc,usec
     d init            pr
     d tobrowser       pr                  extproc('QtmhWrStout')
     d  data                               like(outxml)
     d  length                       10i 0 const
     d  error                              like(gerror)
     d getFirstNames   pr           500a
     d                               20a
     
//--------------------------------------------------------------------
      // Data Structures
     
//--------------------------------------------------------------------
     d gerror          ds                  qualified
     d  bytesp                       10i 0 inz(56)
     d  bytesa                       10i 0
     d  msgid                         7
     d  reserved                      1
     d  data                         40
     
//--------------------------------------------------------------------
      // Global Variables
     
//--------------------------------------------------------------------
     d path            s           1024a   inz
     d q               s             20a   inz
     d q2              s             20a   inz
     d outxml          s            256a
      /copy qrpglesrc,#constants
     
//--------------------------------------------------------------------
      // main
     
//--------------------------------------------------------------------
      /free
       init();
       if q = *blanks;
         outxml = 'Content-Type: text/plain' + x'1515' + '&nbsp;';
       else;
         q2 = %trim(q) + '%';
         outxml = 'Content-Type: text/plain' + x'1515' +
                  getFirstNames(q2);
       endif;
       tobrowser(outxml:%len(%trim(outxml)):gerror);
       return;
      /end-free
     
//--------------------------------------------------------------------
      // init
     
//--------------------------------------------------------------------
     pinit             b
     d                 pi
      /copy qcopysrc,prolog3
      /free
       q = zhbgetvar('q');
      /end-free
     pinit             e
     
//--------------------------------------------------------------------
      // getFirstNames
     
//--------------------------------------------------------------------
     pgetFirstNames    b
     d                 pi           500a
     d parm                          20a
     d string          s            500a   inz
     d name            s             50a   inz
     d spacepos        s              2p 0 inz
     c/exec sql
      + declare names cursor for
      +  select distinct usrdesc
      +   from nalcustom/users
      +    where usrdesc like :parm
      +     order by usrdesc
     c/end-exec
      /free
       exsr $open;
       exsr $fetch;
       dow sqlcod = 0;
         spacepos = %scan(' ':name);
         if spacepos > 0 and %scan(%subst(name:1:spacepos-1):string) = 0;
           string = %trim(string) + %subst(name:1:spacepos-1) + '<br>';
         endif;
         exsr $fetch;
       enddo;
       exsr $close;
       return string;
      /end-free
     
//--------------------------------------------------------------------
      // $open
     
//--------------------------------------------------------------------
     c     $open         begsr
     c/exec sql
      + open names
     c/end-exec
     c                   endsr
     
//--------------------------------------------------------------------
      // $fetch
     
//--------------------------------------------------------------------
     c     $fetch        begsr
     c/exec sql
      + fetch from names into :name
     c/end-exec
     c                   endsr
     
//--------------------------------------------------------------------
      // $close
     
//--------------------------------------------------------------------
     c     $close        begsr
     c/exec sql
      + close names
     c/end-exec
     c                   endsr
     pgetFirstNames    e


Thanks again to all who helped me...hope this helps others...

Shane Cessna
--
This is the Web Enabling the AS400 / iSeries (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/web400.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.