Some experiments with web applications
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.2 KiB

  1. /**
  2. * Created with JetBrains WebStorm.
  3. * User: torsten
  4. * Date: 28.03.13
  5. * Time: 23:07
  6. * To change this template use File | Settings | File Templates.
  7. */
  8. var gcf = {
  9. // decode special characters with their utf-8 representation
  10. decodeHtml : function (token) {
  11. var i,
  12. y,
  13. start = [33, 58, 91, 123, 161],
  14. stop = [47, 64, 96, 126, 255],
  15. startLength = start.length;
  16. for (y = 0; y < startLength; y++) {
  17. for (i = start[y]; i <= stop[y]; i++) {
  18. token = token.replace("&#" + i +";", String.fromCharCode(255));
  19. }
  20. }
  21. return token;
  22. },
  23. // xmlhttp object function
  24. getHTTPObject : function () {
  25. // debug log
  26. if (DEBUG === 1) {console.log("xml http object function");}
  27. // variable definitions
  28. var xhr;
  29. // check for availibility if xmlhttprequest object
  30. if(window.XMLHttpRequest) {
  31. xhr = new XMLHttpRequest();
  32. } else if(window.ActiveXObject) {
  33. xhr = new ActiveXObject("Msxml2.XMLHTTP");
  34. }
  35. return xhr;
  36. },
  37. // ajax call function
  38. ajaxCall : function (dataUrl, outputElement, callback, responseType) {
  39. // debug log
  40. if (DEBUG === 1) {console.log("ajax function");}
  41. // variable definitions
  42. var response,
  43. request = this.getHTTPObject(); // get the xmlhttp object which is supported
  44. outputElement.innerHTML = "Lade Daten ...";
  45. request.onreadystatechange = function() {
  46. if(request.readyState === 4 && request.status === 200) {
  47. //save ajax response
  48. if (responseType === "json") {
  49. response = JSON.parse(request.responseText);
  50. } else if (responseType === "xml") {
  51. response = request.responseXML;
  52. } else {
  53. response = request.responseText;
  54. }
  55. // check if callback is a function
  56. if(typeof callback === "function") {
  57. callback(response);
  58. }
  59. }
  60. };
  61. request.open("get", dataUrl, true);
  62. request.send(null);
  63. }
  64. }