summaryrefslogtreecommitdiffstats
path: root/examples/ajax-broker/helpers.js
diff options
context:
space:
mode:
authorDavid Veenstra <davidjulianveenstra@gmail.com>2015-09-12 14:03:05 +0200
committerArnold Daniels <arnold@jasny.net>2015-09-27 16:54:19 +0200
commit09250d81225398ec8e8b07191c74a8f82df9578d (patch)
tree4c766c2a4ad9881f485a47a497436c5e1d0f438e /examples/ajax-broker/helpers.js
parentc2932ac5e26c3aad4a5738a32531fb1a59760a46 (diff)
downloadsso-09250d81225398ec8e8b07191c74a8f82df9578d.zip
sso-09250d81225398ec8e8b07191c74a8f82df9578d.tar.gz
sso-09250d81225398ec8e8b07191c74a8f82df9578d.tar.bz2
work for #13 #14 #15: tests, cacheing, examples
Diffstat (limited to 'examples/ajax-broker/helpers.js')
-rw-r--r--examples/ajax-broker/helpers.js66
1 files changed, 41 insertions, 25 deletions
diff --git a/examples/ajax-broker/helpers.js b/examples/ajax-broker/helpers.js
index 5e1b4c3..95b5d0e 100644
--- a/examples/ajax-broker/helpers.js
+++ b/examples/ajax-broker/helpers.js
@@ -1,41 +1,57 @@
-function microAjax(B,A){this.bindFunction=function(E,D){return function(){return E.apply(D,[D]);};};this.stateChange=function(D){if(this.request.readyState==4){this.callbackFunction(this.request.responseText);}};this.getRequest=function(){if(window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}else{if(window.XMLHttpRequest){return new XMLHttpRequest();}}return false;};this.postBody=(arguments[2]||"");this.callbackFunction=A;this.url=B;this.request=this.getRequest();if(this.request){var C=this.request;C.onreadystatechange=this.bindFunction(this.stateChange,this);if(this.postBody!==""){C.open("POST",B,true);C.setRequestHeader("X-Requested-With","XMLHttpRequest");C.setRequestHeader("Content-type","application/x-www-form-urlencoded");C.setRequestHeader("Connection","close");}else{C.open("GET",B,true);}C.send(this.postBody);}};
+function microAjax(B,A)
+{
+ this.bindFunction=function (E,D) {
+ return function () {
+ return E.apply(D,[D]);};};this.stateChange=function (D) {
+ if (this.request.readyState==4) {
+ this.callbackFunction(this.request.responseText);}};this.getRequest=function () {
+ if (window.ActiveXObject) {
+ return new ActiveXObject("Microsoft.XMLHTTP");} else {
+ if (window.XMLHttpRequest) {
+ return new XMLHttpRequest();}}return false;};this.postBody=(arguments[2]||"");this.callbackFunction=A;this.url=B;this.request=this.getRequest();if (this.request) {
+ var C=this.request;C.onreadystatechange=this.bindFunction(this.stateChange,this);if (this.postBody!=="") {
+ C.open("POST",B,true);C.setRequestHeader("X-Requested-With","XMLHttpRequest");C.setRequestHeader("Content-type","application/x-www-form-urlencoded");C.setRequestHeader("Connection","close");} else {
+ C.open("GET",B,true);}C.send(this.postBody);}};
var token;
-function attachSession() {
- microAjax('/examples/ajax-broker/ajax.php?command=attach&token='+ token, function(data) {
- console.log(data);
- });
+function attachSession()
+{
+ microAjax('/examples/ajax-broker/ajax.php?command=attach&token='+ token, function (data) {
+ console.log(data);
+ });
}
-function getToken(f) {
- microAjax('/examples/ajax-broker/ajax.php?command=getToken', function(data) {
- token = data;
- console.log('token is ready');
- });
+function getToken(f)
+{
+ microAjax('/examples/ajax-broker/ajax.php?command=getToken', function (data) {
+ token = data;
+ console.log('token is ready');
+ });
}
-function login() {
- var username = document.querySelector('input[name="username"]').value;
- var password = document.querySelector('input[name="password"]').value;
- var query = [
+function login()
+{
+ var username = document.querySelector('input[name="username"]').value;
+ var password = document.querySelector('input[name="password"]').value;
+ var query = [
'command=login',
'username='+username,
'password='+password,
'token='+token
- ];
+ ];
- microAjax('/examples/ajax-broker/ajax.php?' + query.join('&'), function(data) {
- console.log(data);
- var outputDiv = document.querySelector('#output');
- var output = "";
- var jsonData = JSON.parse(data);
+ microAjax('/examples/ajax-broker/ajax.php?' + query.join('&'), function (data) {
+ console.log(data);
+ var outputDiv = document.querySelector('#output');
+ var output = "";
+ var jsonData = JSON.parse(data);
- for (var key in jsonData) {
- output += key + ": " + jsonData[key] + "<br>";
- }
- outputDiv.innerHTML = output;
- });
+ for (var key in jsonData) {
+ output += key + ": " + jsonData[key] + "<br>";
+ }
+ outputDiv.innerHTML = output;
+ });
}
getToken();