source: greenstone3/trunk/web/gs_ajax_utils.js@ 18343

Last change on this file since 18343 was 10695, checked in by kjdon, 19 years ago

Dave's basic AJAX search stuff

  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1
2
3function loadAsync(sUri, SOAPMessage) {
4 var xmlHttp = XmlHttp.create();
5 var async = true;
6 xmlHttp.open("POST", sUri, async);
7 xmlHttp.onreadystatechange = function () {
8 if (xmlHttp.readyState == 4){
9 var result = xmlHttp.responseText;
10 getTitle2(xmlHttp.responseXML, xmlHttp.responseText);
11 }
12 }
13 xmlHttp.setRequestHeader("SOAPAction", " ");
14 xmlHttp.setRequestHeader("Content-Type", "Content-Type: text/xml; charset=utf-8");
15
16 xmlHttp.send(SOAPMessage);
17}
18
19
20function messageToSOAP(message) {
21 soapBody = '<soapenv:Body>' + message + '</soapenv:Body>'
22 soap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' + soapBody + '</soapenv:Envelope>'
23 x= '<?xml version="1.0" encoding="UTF-8"?>' + soap;
24 return x;
25}
26
27
28
29
30function getText(element) { //get the text from possibly multiple text nodes
31if (element.hasChildNodes()) {
32 tempString = '';
33 for (j=0; j < element.childNodes.length; j++) {
34 if (element.childNodes[j].nodeType == Node.TEXT_NODE ) { // =2
35 tempString += element.childNodes[j].nodeValue;
36 }
37 else {
38 tempString += 'non text node: ';
39 }
40 }
41 return tempString;
42}
43else {
44 return 'getText: element has no ChildNodes from which to extract Text';
45}
46}
47
48
49function newOpenTag(name) {
50 return '<' + name + '>';
51}
52
53function newCloseTag(name) {
54 return '</' + name + '>';
55}
56
57function newEmptyTag(name) {
58 return '<' + name + '/>';
59}
60
61function newElement(name, content) {
62 e = '<' + name + '>' + content;
63 e += '</' + name + '>';
64 return e;
65}
66
67
68function newElementAtt1(name, content, attName, attValue) {
69 e = '<' + name + ' ' + attName + '="' + attValue +'">' + content;
70 e += '</' + name + '>';
71 return e;
72}
73
74
75
76
77function newElementAtt(name, content, nameArray, valueArray) {
78 e = '<' + name + ' ' ;
79 for (i=0; i < nameArray.length; i++) {
80 e += newAttribute(nameArray[i], valueArray[i])
81 }
82 e += '>' + content;
83 e += '</' + name + '>';
84 return e;
85}
86
87
88function newAttribute(name, value) {
89 return ' ' + name + '="' + value + '"';
90}
91
92/*
93var a = [];
94var b = [];
95a[0] = 'title';
96b[0] = 'test';
97a[1] = 'title2';
98b[1] = 'test2';
99
100alert( newElement('message', 'some content', a=[], b=[]));
101
102*/
103
104function countElementChildren(node) {
105 count= 0;
106 childList = node.childNodes;
107 for(var i=0; i < (childList.length); i++) {
108 childNode = childList.item(i);
109 if ((childNode.nodeType == 1)) { // only count elements
110 count++;
111 }
112 }
113 return count;
114}
115
116function removeAllChildren(node) {
117 while (node.hasChildNodes()) {
118 node.removeChild(node.firstChild);
119 }
120}
121
122
123function isElement(node) {
124 if (node.nodeType == 1) {
125 return true; }
126 else {
127 return false;
128 }
129}
Note: See TracBrowser for help on using the repository browser.