+ Util.request
authortgambet
Wed, 24 Aug 2011 17:10:36 -0400
changeset 46 c96c92e92021
parent 45 755f31ee62aa
child 47 c12248cd29ee
+ Util.request
src/main/resources/scripts/Utils.js
--- a/src/main/resources/scripts/Utils.js	Wed Aug 24 15:46:07 2011 -0400
+++ b/src/main/resources/scripts/Utils.js	Wed Aug 24 17:10:36 2011 -0400
@@ -134,5 +134,25 @@
       }
       return result;
     }
+  },
+  
+  request : function (uri, body, callback, async) {
+  	body = body ? body : null;
+    callback = callback ? callback : null;
+    //async = typeof(async) != 'undefined' ? async : false;
+    async = !!async;
+  	var http = new XMLHttpRequest();
+	http.open('GET', uri, async);
+	http.onreadystatechange = function () {
+		console.log("state: " + http.readyState);
+		if(http.readyState == 4 && http.status == 200){
+			if (callback != null)
+				callback(http.responseText);
+		}
+	};
+	http.send(body);
+	if (async == false)
+		return http.responseText;
   }
+  
 };