Subject: Web vs client
Not to be trite, but this looks like it might be an excellent time to learn about Javascript and AJAX/or JSON since they are perfect for what you are trying to do. With a well thought-out framework, you can simplify the process to a very simple procedure:
-
Trigger javascript function via a button or other form process.
-
This function sets up a url to your agent and initializes the objects you need to make AJAX calls (if you’re using AJAX, you need the xmlhttprequest object… or you could use JSON).
Here is an ajax call I use often. It passes parameters to the agent via the url for filename, viewunid (both are global variables) and a reference view unid (which is a local variable and is passed to the function in the call).
function populateViewArray(refviewunid){
//populate the view div in the nav bar with links to all of the views, in alphabetical order.
var url = “agtGetViewsProd?openagent&dbname=” + filename + “&viewunid=” + refviewunid;
initRequest(url);
//window.alert("got this far");
req.onreadystatechange = processViews; //this is the callback function where you handle your xml return to update the fields.
req.open("GET", url, true); //this triggers the agent (though it can also be a view formatted as xml)
req.send(null);
}
-
The call is made to your agent via the url (te req.open in # 2 above). You can simply modify your code so that, instead of writing to the document, you use print statements and build your xml that is returned.
-
The javascript function then passes control to another function to parse the returned xml (the req.onreadystatechange in # 2 above)
-
The parser function called by onreadystatechange takes each piece of xml and places the text in the appropriate field
For example… from your example, you would want the xml returned by the agent in a manner something like this:
strReturnMesg contains any status messages you want to display on your form and can be left blank or left out. The carriage returns at the end of each line are used only for formatting (I often use an alert box or print my return to a div on the page for testing and having each xml entity on its own line allows for improved debugging).
d_b = “<doc_broj>” + vwdoc.doc_broj(0) + “</doc_broj>”
un = “” + usrnm + “”
brjUgvr = “” + brjUgvr+ “”
strReturnResults = d_b + un + brjUgvr 'This variable simply makes it easier to use these three elements together.
Dim outputstring As String
outputstring$ = "Content-Type: text/xml" + Chr$(10)
outputstring$ = outputstring$ + {<?xml version="1.0" ?>} + Chr$(10)
outputstring$ = outputstring$ + {<data>} + Chr$(10)
outputstring$ = outputstring$ +{<message>} + Chr$(10)
outputstring$ = outputstring$ + strReturnMsg + Chr$(10)
outputstring$ = outputstring$ +{</message>} + Chr$(10)
If strReturnResults <> "" Then
outputstring$ = outputstring$ + strReturnResults + Chr$(10)
End If
outputstring$ = outputstring$ + {</checkinfo>} + Chr$(10)
'The cache-control statement will prevent the xml from being cached on the page.
Print "Cache-Control: no-cache"
'Return the xml so it can be parsed by the javascript function on the form
Print outputstring$ 'this returns the xml to the javascript callback function
A useful technique in the callback function, is to throw an alert with req.responseText in it to display the xml/html/text that you obtained from the agent. This will show you that you have the data you expect. A search on AJAX requests will give you a list of common HTTP messages that you should trap for in your callback function.