Showing
6 changed files
with
103 additions
and
87 deletions
@@ -14,8 +14,9 @@ class dummy extends c_xmlify | @@ -14,8 +14,9 @@ class dummy extends c_xmlify | ||
14 | protected $var1; | 14 | protected $var1; |
15 | protected $var2; | 15 | protected $var2; |
16 | protected $var3; | 16 | protected $var3; |
17 | + protected $var4; | ||
17 | 18 | ||
18 | - function __construct ($xr = NULL, $v1, $v2, $v3) | 19 | + function __construct ($xr = NULL, $v1, $v2, $v3, $v4) |
19 | { | 20 | { |
20 | if ($xr !== NULL) | 21 | if ($xr !== NULL) |
21 | parent::__construct ($xr); | 22 | parent::__construct ($xr); |
@@ -23,11 +24,13 @@ class dummy extends c_xmlify | @@ -23,11 +24,13 @@ class dummy extends c_xmlify | ||
23 | $this->var1 = $v1; | 24 | $this->var1 = $v1; |
24 | $this->var2 = $v2; | 25 | $this->var2 = $v2; |
25 | $this->var3 = $v3; | 26 | $this->var3 = $v3; |
27 | + $this->var4 = $v4; | ||
26 | } | 28 | } |
27 | }; | 29 | }; |
28 | 30 | ||
29 | $_data = new dummy ( | 31 | $_data = new dummy ( |
30 | - NULL, array ('var1'=>0.53, 'var2'=>1.1), array (12, 13), "Hallo"); | 32 | + NULL, array ('var1'=>0.53, 'var2'=>1.1), array (12, 13), "Hallo", |
33 | + new dummy (NULL, "Das", "ist", "ein", "test")); | ||
31 | 34 | ||
32 | //$_data = array (array ('var1'=>0.53, 'var2'=>1.1), array (12, 13), "Hallo"); | 35 | //$_data = array (array ('var1'=>0.53, 'var2'=>1.1), array (12, 13), "Hallo"); |
33 | 36 |
js/callbacks.js
0 → 100644
1 | +if (typeof (nBildertool) === 'undefined') | ||
2 | + nBildertool = {}; | ||
3 | + | ||
4 | +nBildertool.cbCommon = function () | ||
5 | +{ | ||
6 | + switch (nBildertool.req.readyState) | ||
7 | + { | ||
8 | + case 4: | ||
9 | + if (nBildertool.req.status != 200) | ||
10 | + alert ("Fehler:" + nBildertool.req.status); | ||
11 | + else | ||
12 | + { | ||
13 | + data = nBildertool.deXmlify (nBildertool.req.responseXML); | ||
14 | + console.dir (data); | ||
15 | + } | ||
16 | + return true; | ||
17 | + | ||
18 | + default: | ||
19 | + return false; | ||
20 | + } | ||
21 | +} |
1 | -function extend (subClass, baseClass) | 1 | +if (typeof (nBildertool) === 'undefined') |
2 | + nBildertool = {}; | ||
3 | + | ||
4 | +nBildertool.extend = function (subClass, baseClass) | ||
2 | { | 5 | { |
3 | function inheritance() {} | 6 | function inheritance() {} |
4 | inheritance.prototype = baseClass.prototype; | 7 | inheritance.prototype = baseClass.prototype; |
js/service.js
0 → 100644
1 | +if (typeof (nBildertool) === 'undefined') | ||
2 | + nBildertool = {}; | ||
3 | + | ||
4 | +nBildertool.req = null; | ||
5 | + | ||
6 | +nBildertool.service = function (url, callback) | ||
7 | +{ | ||
8 | + // erstellen des requests | ||
9 | + | ||
10 | + try | ||
11 | + { | ||
12 | + nBildertool.req = new XMLHttpRequest(); | ||
13 | + } | ||
14 | + catch (e) | ||
15 | + { | ||
16 | + try | ||
17 | + { | ||
18 | + nBildertool.req = new ActiveXObject("Msxml2.XMLHTTP"); | ||
19 | + } | ||
20 | + catch (e) | ||
21 | + { | ||
22 | + try | ||
23 | + { | ||
24 | + nBildertool.req = new ActiveXObject("Microsoft.XMLHTTP"); | ||
25 | + } | ||
26 | + catch (failed) | ||
27 | + { | ||
28 | + nBildertool.req = null; | ||
29 | + } | ||
30 | + } | ||
31 | + } | ||
32 | + | ||
33 | + if (nBildertool.req == null) | ||
34 | + alert("Error creating request object!"); | ||
35 | + | ||
36 | + nBildertool.req.open("GET", url, true); | ||
37 | + | ||
38 | + // Beim abschliessen des request wird diese Funktion ausgeführt | ||
39 | + if (typeof (callback) === 'undefined') | ||
40 | + nBildertool.req.onreadystatechange = nBildertool.cbCommon; | ||
41 | + else | ||
42 | + nBildertool.req.onreadystatechange = callback; | ||
43 | + | ||
44 | + nBildertool.req.setRequestHeader("Content-Type", | ||
45 | + "application/x-www-form-urlencoded"); | ||
46 | + | ||
47 | + nBildertool.req.send(null); | ||
48 | +} |
1 | -function xmlToVar (data) | 1 | +if (typeof (nBildertool) === 'undefined') |
2 | + nBildertool = {}; | ||
3 | + | ||
4 | +nBildertool.xmlToVar = function (data) | ||
2 | { | 5 | { |
3 | if (!data.hasChildNodes ()) | 6 | if (!data.hasChildNodes ()) |
4 | return null; | 7 | return null; |
@@ -25,7 +28,7 @@ function xmlToVar (data) | @@ -25,7 +28,7 @@ function xmlToVar (data) | ||
25 | return ret; | 28 | return ret; |
26 | } | 29 | } |
27 | 30 | ||
28 | -function xmlToObjectArray (data) | 31 | +nBildertool.xmlToObjectArray = function (data) |
29 | { | 32 | { |
30 | var ret = new Array (); | 33 | var ret = new Array (); |
31 | 34 | ||
@@ -43,16 +46,16 @@ function xmlToObjectArray (data) | @@ -43,16 +46,16 @@ function xmlToObjectArray (data) | ||
43 | switch (child.nodeName) | 46 | switch (child.nodeName) |
44 | { | 47 | { |
45 | case 'variable': | 48 | case 'variable': |
46 | - ret[name] = xmlToVar (child); break; | 49 | + ret[name] = nBildertool.xmlToVar (child); break; |
47 | case 'array': | 50 | case 'array': |
48 | - ret[name] = xmlToArray (child); break; | 51 | + ret[name] = nBildertool.xmlToArray (child); break; |
49 | case 'class': | 52 | case 'class': |
50 | var cName = child.getAttribute ('class'); | 53 | var cName = child.getAttribute ('class'); |
51 | 54 | ||
52 | if (typeof (eval (cName)) === 'function') | 55 | if (typeof (eval (cName)) === 'function') |
53 | ret[name] = eval ("new " + cName + "(child)"); | 56 | ret[name] = eval ("new " + cName + "(child)"); |
54 | else | 57 | else |
55 | - ret[name] = xmlToObjectArray (child); | 58 | + ret[name] = nBildertool.xmlToObjectArray (child); |
56 | } | 59 | } |
57 | } | 60 | } |
58 | } | 61 | } |
@@ -60,7 +63,7 @@ function xmlToObjectArray (data) | @@ -60,7 +63,7 @@ function xmlToObjectArray (data) | ||
60 | return ret; | 63 | return ret; |
61 | } | 64 | } |
62 | 65 | ||
63 | -function xmlToArray (data) | 66 | +nBildertool.xmlToArray = function (data) |
64 | { | 67 | { |
65 | var ret = new Array (); | 68 | var ret = new Array (); |
66 | 69 | ||
@@ -84,16 +87,16 @@ function xmlToArray (data) | @@ -84,16 +87,16 @@ function xmlToArray (data) | ||
84 | switch (_child.nodeName) | 87 | switch (_child.nodeName) |
85 | { | 88 | { |
86 | case 'variable': | 89 | case 'variable': |
87 | - ret[key] = xmlToVar (_child); break; | 90 | + ret[key] = nBildertool.xmlToVar (_child); break; |
88 | case 'array': | 91 | case 'array': |
89 | - ret[key] = xmlToArray (_child); break; | 92 | + ret[key] = nBildertool.xmlToArray (_child); break; |
90 | case 'class': | 93 | case 'class': |
91 | var cName = child.getAttribute ('class'); | 94 | var cName = child.getAttribute ('class'); |
92 | 95 | ||
93 | if (typeof (eval (cName)) === 'function') | 96 | if (typeof (eval (cName)) === 'function') |
94 | ret[key] = eval ("new " + cName + "(child)"); | 97 | ret[key] = eval ("new " + cName + "(child)"); |
95 | else | 98 | else |
96 | - ret[key] = xmlToObjectArray (child); | 99 | + ret[key] = nBildertool.xmlToObjectArray (child); |
97 | } | 100 | } |
98 | } | 101 | } |
99 | } | 102 | } |
@@ -103,7 +106,7 @@ function xmlToArray (data) | @@ -103,7 +106,7 @@ function xmlToArray (data) | ||
103 | return ret; | 106 | return ret; |
104 | } | 107 | } |
105 | 108 | ||
106 | -function c_xmlify (data) | 109 | +nBildertool.c_xmlify = function (data) |
107 | { | 110 | { |
108 | if (! data.hasChildNodes ()) | 111 | if (! data.hasChildNodes ()) |
109 | return; | 112 | return; |
@@ -121,23 +124,23 @@ function c_xmlify (data) | @@ -121,23 +124,23 @@ function c_xmlify (data) | ||
121 | switch (child.nodeName) | 124 | switch (child.nodeName) |
122 | { | 125 | { |
123 | case 'variable': | 126 | case 'variable': |
124 | - this[name] = xmlToVar (child); break; | 127 | + this[name] = nBildertool.xmlToVar (child); break; |
125 | case 'array': | 128 | case 'array': |
126 | - this[name] = xmlToArray (child); break; | 129 | + this[name] = nBildertool.xmlToArray (child); break; |
127 | case 'class': | 130 | case 'class': |
128 | var cName = child.getAttribute ('class'); | 131 | var cName = child.getAttribute ('class'); |
129 | 132 | ||
130 | if (typeof (eval (cName)) === 'function') | 133 | if (typeof (eval (cName)) === 'function') |
131 | this[name] = eval ("new " + cName + "(child)"); | 134 | this[name] = eval ("new " + cName + "(child)"); |
132 | else | 135 | else |
133 | - this[name] = xmlToObjectArray (child); | 136 | + this[name] = nBildertool.xmlToObjectArray (child); |
134 | } | 137 | } |
135 | } | 138 | } |
136 | } | 139 | } |
137 | } | 140 | } |
138 | } | 141 | } |
139 | 142 | ||
140 | -function deXmlify (data) | 143 | +nBildertool.deXmlify = function (data) |
141 | { | 144 | { |
142 | var ret = null; | 145 | var ret = null; |
143 | var child = data.firstChild; | 146 | var child = data.firstChild; |
@@ -145,16 +148,16 @@ function deXmlify (data) | @@ -145,16 +148,16 @@ function deXmlify (data) | ||
145 | switch (child.nodeName) | 148 | switch (child.nodeName) |
146 | { | 149 | { |
147 | case 'variable': | 150 | case 'variable': |
148 | - ret = xmlToVar (child); break; | 151 | + ret = nBildertool.xmlToVar (child); break; |
149 | case 'array': | 152 | case 'array': |
150 | - ret = xmlToArray (child); break; | 153 | + ret = nBildertool.xmlToArray (child); break; |
151 | case 'class': | 154 | case 'class': |
152 | var cName = child.getAttribute ('class'); | 155 | var cName = child.getAttribute ('class'); |
153 | 156 | ||
154 | if (typeof (eval (cName)) === 'function') | 157 | if (typeof (eval (cName)) === 'function') |
155 | ret = eval ("new " + cName + "(child)"); | 158 | ret = eval ("new " + cName + "(child)"); |
156 | else | 159 | else |
157 | - ret = xmlToObjectArray (child); | 160 | + ret = nBildertool.xmlToObjectArray (child); |
158 | } | 161 | } |
159 | 162 | ||
160 | return ret; | 163 | return ret; |
@@ -7,12 +7,11 @@ | @@ -7,12 +7,11 @@ | ||
7 | 7 | ||
8 | <script src="js/helper.js" type="text/javascript"></script> | 8 | <script src="js/helper.js" type="text/javascript"></script> |
9 | <script src="js/xmlify.js" type="text/javascript"></script> | 9 | <script src="js/xmlify.js" type="text/javascript"></script> |
10 | + <script src="js/service.js" type="text/javascript"></script> | ||
11 | + <script src="js/callbacks.js" type="text/javascript"></script> | ||
10 | 12 | ||
11 | <script type="text/javascript"> | 13 | <script type="text/javascript"> |
12 | //<![CDATA[ | 14 | //<![CDATA[ |
13 | - var req = null; | ||
14 | - var data; | ||
15 | - | ||
16 | function dummy (data) | 15 | function dummy (data) |
17 | { | 16 | { |
18 | this.var1 = null; | 17 | this.var1 = null; |
@@ -22,69 +21,7 @@ | @@ -22,69 +21,7 @@ | ||
22 | 21 | ||
23 | dummy.baseConstructor.call (this, data); | 22 | dummy.baseConstructor.call (this, data); |
24 | } | 23 | } |
25 | - extend (dummy, c_xmlify); | ||
26 | - | ||
27 | - function getData () | ||
28 | - { | ||
29 | - switch (req.readyState) | ||
30 | - { | ||
31 | - case 4: | ||
32 | - if (req.status != 200) | ||
33 | - alert ("Fehler:" + req.status); | ||
34 | - else | ||
35 | - data = deXmlify (req.responseXML); | ||
36 | - console.dir (data); | ||
37 | - return true; | ||
38 | - | ||
39 | - default: | ||
40 | - return false; | ||
41 | - } | ||
42 | - } | ||
43 | - | ||
44 | - function updData () | ||
45 | - { | ||
46 | - // erstellen des requests | ||
47 | - | ||
48 | - try | ||
49 | - { | ||
50 | - req = new XMLHttpRequest(); | ||
51 | - } | ||
52 | - catch (e) | ||
53 | - { | ||
54 | - try | ||
55 | - { | ||
56 | - req = new ActiveXObject("Msxml2.XMLHTTP"); | ||
57 | - } | ||
58 | - catch (e) | ||
59 | - { | ||
60 | - try | ||
61 | - { | ||
62 | - req = new ActiveXObject("Microsoft.XMLHTTP"); | ||
63 | - } | ||
64 | - catch (failed) | ||
65 | - { | ||
66 | - req = null; | ||
67 | - } | ||
68 | - } | ||
69 | - } | ||
70 | - | ||
71 | - if (req == null) | ||
72 | - alert("Error creating request object!"); | ||
73 | - | ||
74 | - // anfrage erstellen (GET, url ist localhost, | ||
75 | - // request ist asynchron | ||
76 | - var url = 'http://localhost/~georg/bilder/ajax+json/ajax.php'; | ||
77 | - | ||
78 | - req.open("GET", url, true); | ||
79 | - | ||
80 | - // Beim abschliessen des request wird diese Funktion ausgeführt | ||
81 | - req.onreadystatechange = getData; | ||
82 | - | ||
83 | - req.setRequestHeader("Content-Type", | ||
84 | - "application/x-www-form-urlencoded"); | ||
85 | - | ||
86 | - req.send(null); | ||
87 | - } | 24 | + nBildertool.extend (dummy, nBildertool.c_xmlify); |
88 | //]]> | 25 | //]]> |
89 | </script> | 26 | </script> |
90 | </head> | 27 | </head> |
@@ -92,7 +29,8 @@ | @@ -92,7 +29,8 @@ | ||
92 | <body> | 29 | <body> |
93 | <script language="javascript"> | 30 | <script language="javascript"> |
94 | //<![CDATA[ | 31 | //<![CDATA[ |
95 | - updData (); | 32 | + var serviceUrl = 'http://localhost/~georg/bilder/ajax+json/ajax.php' |
33 | + nBildertool.service (serviceUrl); | ||
96 | console.log ('%s', 'jokus'); | 34 | console.log ('%s', 'jokus'); |
97 | //]]> | 35 | //]]> |
98 | </script> | 36 | </script> |
Please
register
or
login
to post a comment