##
Multiple ServerFrames

So my remark that all communication between browser and server in MapClient should be done by hidden variables is not strictly true. CGI variables have to be sent as form variables, but whatever the server sends back can be read via the DOM interface. "s.getVar(name)" is just short for:

    s.contentWindow.document.getElementsByTagName("form")[0]["name"].value.

In fact, all basic window examples were hybrids: MapServer returned a template file with an actual image, and a few variables. The image was displayed in the window's (visible) displayframe and the variables were read out by getReturnedVar(). For complex applications, however, I prefer to exchange all information via invisible source/target serverFrames. The problem is that a WebServer request is a one-shot operation: it always completely replaces the target in the browser. In traditional web programming a complete new page is built up in the browser after every web request. In more modern browsers pages can be divided in frames and iframes, but these too have to be continually initialized. This not only causes very flickering (and slow) webpages, it also makes it very hard to program a complete application, especially because there is no persistance between server requests.
An unlimited number of serverFrames can be attached to window with the win method "addServerFrame()". Each window has an internal array, called serverFrames[]. The first element, serverFrames[0] is reserved for use by the win methods "setVar()" etc., and has as default target the visible displayframe of the window. The call "w.setVar()" is actually equivalent to "w.serverFrames[0].setVar()". All other serverFrames, starting from "serverFrames[1], can set targets, submit requests and execute onReturn functions. When a complete window is submitted, all serverFrames that have a server specified with "setServerURL()" are submitted at the same time, and all callback functions are executed when these requests return. The leftmost button of the window will turn red before the first submit, and grey after the last server request has returned. As an example I rewrote the previous example in
, to use serverFrames internal to the window.