Changeset 24061
- Timestamp:
- 2011-05-20T09:32:50+12:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/gs_ajax_utils.js
r10695 r24061 1 /* 2 function loadAsync(sUri, SOAPMessage) { 3 var xmlHttp = XmlHttp.create(); 4 xmlHttp.open("POST", sUri, true); 5 xmlHttp.onreadystatechange = function () { 6 if (xmlHttp.readyState == 4){ 7 getTitle2(xmlHttp.responseXML, xmlHttp.responseText); 8 } 9 } 10 xmlHttp.setRequestHeader("SOAPAction", " "); 11 xmlHttp.setRequestHeader("Content-Type", "Content-Type: text/xml; charset=utf-8"); 1 12 13 xmlHttp.send(SOAPMessage); 14 } 15 */ 2 16 3 function 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 function messageToSOAP(message) { 18 return ['<?xml version="1.0" encoding="UTF-8"?>', 19 '<soapenv:Envelope ', 20 'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"', 21 'xmlns:xsd="http://www.w3.org/2001/XMLSchema"', 22 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">', 23 '<soapenv:Body>', 24 message, 25 '</soapenv:Body>', 26 '</soapenv:Envelope>'].join(""); 17 27 } 18 28 19 20 function 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; 29 function getText(element) { //get the text from possibly multiple text nodes 30 if (element.hasChildNodes()) { 31 var tempString = []; 32 for (var j = 0; j < element.childNodes.length; j++) { 33 if (element.childNodes[j].nodeType == Node.TEXT_NODE ) { // =2 34 tempString.push(element.childNodes[j].nodeValue); 35 } 36 else { 37 tempString.push('non text node: '); 38 } 39 } 40 return tempString.join(""); 41 } 42 else { 43 return 'getText: element has no ChildNodes from which to extract Text'; 44 } 25 45 } 26 46 27 28 29 30 function getText(element) { //get the text from possibly multiple text nodes31 if (element.hasChildNodes()) {32 tempString = '';33 for (j=0; j < element.childNodes.length; j++) {34 if (element.childNodes[j].nodeType == Node.TEXT_NODE ) { // =235 tempString += element.childNodes[j].nodeValue;36 }37 else {38 tempString += 'non text node: ';39 }40 }41 return tempString;42 }43 else {44 return 'getText: element has no ChildNodes from which to extract Text';45 }46 }47 48 49 47 function newOpenTag(name) { 50 return '<' + name + '>';48 return ['<', name, '>'].join(""); 51 49 } 52 50 53 51 function newCloseTag(name) { 54 return '</' + name + '>';52 return ['</', name, '>'].join(""); 55 53 } 56 54 57 55 function newEmptyTag(name) { 58 return '<' + name + '/>';56 return ['<', name, '/>'].join(""); 59 57 } 60 58 61 59 function newElement(name, content) { 62 e = '<' + name + '>' + content; 63 e += '</' + name + '>'; 64 return e; 60 return ['<', name, '>', content, '</', name, '>'].join(""); 65 61 } 66 62 67 68 63 function newElementAtt1(name, content, attName, attValue) { 69 e = '<' + name + ' ' + attName + '="' + attValue +'">' + content; 70 e += '</' + name + '>'; 71 return e; 64 return ['<', name, ' ', attName, '="', attValue, '">', content, '</', name, '>'].join(""); 72 65 } 73 66 74 75 76 77 67 function 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; 68 var e = ['<', name, ' ']; 69 for (i=0; i < nameArray.length; i++) { 70 e.push(newAttribute(nameArray[i], valueArray[i])); 71 } 72 e.push(['>', content, '</', name, '>']); 73 return e.join(""); 85 74 } 86 75 87 88 76 function newAttribute(name, value) { 89 return ' ' + name + '="' + value + '"';77 return [' ', name, '="', value, '"'].join(""); 90 78 } 91 79 92 /*93 var a = [];94 var b = [];95 a[0] = 'title';96 b[0] = 'test';97 a[1] = 'title2';98 b[1] = 'test2';99 100 alert( newElement('message', 'some content', a=[], b=[]));101 102 */103 104 80 function countElementChildren(node) { 105 count= 0;106 childList = node.childNodes;81 var count = 0; 82 var childList = node.childNodes; 107 83 for(var i=0; i < (childList.length); i++) { 108 childNode = childList.item(i);84 var childNode = childList.item(i); 109 85 if ((childNode.nodeType == 1)) { // only count elements 110 86 count++; 111 87 } 112 88 } … … 120 96 } 121 97 122 123 98 function isElement(node) { 124 125 126 127 128 99 if (node.nodeType == 1) { 100 return true; } 101 else { 102 return false; 103 } 129 104 }
Note:
See TracChangeset
for help on using the changeset viewer.