2 * ====================================================================
4 * ====================================================================
5 * Sarissa cross browser XML library - AJAX module
7 * @author: Copyright Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net
9 * This module contains some convinient AJAX tricks based on Sarissa
11 * ====================================================================
13 * ====================================================================
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 or
16 * the GNU Lesser General Public License version 2.1 as published by
17 * the Free Software Foundation (your choice between the two).
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License or GNU Lesser General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * or GNU Lesser General Public License along with this program; if not,
26 * write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * or visit http://www.gnu.org
31 * Update an element with response of a GET request on the given URL.
33 * @param sFromUrl the URL to make the request to
34 * @param oTargetElement the element to update
35 * @param xsltproc (optional) the transformer to use on the returned
36 * content before updating the target element with it
38 Sarissa.updateContentFromURI = function(sFromUrl, oTargetElement, xsltproc) {
40 oTargetElement.style.cursor = "wait";
41 var xmlhttp = new XMLHttpRequest();
42 xmlhttp.open("GET", sFromUrl);
43 function sarissa_dhtml_loadHandler() {
44 if (xmlhttp.readyState == 4) {
45 oTargetElement.style.cursor = "auto";
46 Sarissa.updateContentFromNode(xmlhttp.responseXML, oTargetElement, xsltproc);
49 xmlhttp.onreadystatechange = sarissa_dhtml_loadHandler;
51 oTargetElement.style.cursor = "auto";
54 oTargetElement.style.cursor = "auto";
60 * Update an element's content with the given DOM node.
62 * @param sFromUrl the URL to make the request to
63 * @param oTargetElement the element to update
64 * @param xsltproc (optional) the transformer to use on the given
65 * DOM node before updating the target element with it
67 Sarissa.updateContentFromNode = function(oNode, oTargetElement, xsltproc) {
69 oTargetElement.style.cursor = "wait";
70 Sarissa.clearChildNodes(oTargetElement);
71 // check for parsing errors
72 var ownerDoc = oNode.nodeType == Node.DOCUMENT_NODE?oNode:oNode.ownerDocument;
73 if(ownerDoc.parseError && ownerDoc.parseError != 0) {
74 var pre = document.createElement("pre");
75 pre.appendChild(document.createTextNode(Sarissa.getParseErrorText(ownerDoc)));
76 oTargetElement.appendChild(pre);
79 // transform if appropriate
81 oNode = xsltproc.transformToDocument(oNode);
83 // be smart, maybe the user wants to display the source instead
84 if(oTargetElement.tagName.toLowerCase == "textarea" || oTargetElement.tagName.toLowerCase == "input") {
85 oTargetElement.value = Sarissa.serialize(oNode);
88 // ok that was not smart; it was paranoid. Keep up the good work by trying to use DOM instead of innerHTML
89 if(oNode.nodeType == Node.DOCUMENT_NODE || oNode.ownerDocument.documentElement == oNode) {
90 oTargetElement.innerHTML = Sarissa.serialize(oNode);
93 oTargetElement.appendChild(oTargetElement.ownerDocument.importNode(oNode, true));
102 oTargetElement.style.cursor = "auto";