fork download
  1. importPackage(java.io);
  2. importPackage(java.lang);
  3.  
  4. /* based on xajax Javascript library (http://w...content-available-to-author-only...t.org) */
  5. if (!window.jtajax) {
  6.  
  7. function jtAJAX()
  8. {
  9. this.options = {url: '',type: 'post',nocache: true,data: ''};
  10.  
  11. this.$ = function(id) {if(!id){return null;}var o=document.getElementById(id);if(!o&&document.all){o=document.all[id];}return o;};
  12. this.extend = function(o, e){for(var k in (e||{}))o[k]=e[k];return o;};
  13. this.encode = function(t){return encodeURIComponent(t);};
  14. this.setup = function(options) {this.options = this.extend(this.options, options);};
  15.  
  16. this.xhr = function()
  17. {
  18. var xhr = null;
  19. if ('undefined' != typeof XMLHttpRequest) xhr = new XMLHttpRequest();
  20. if (!xhr && 'undefined' != typeof ActiveXObject) {
  21. var msxmlhttp = new Array('Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
  22. for (var i=0;i<msxmlhttp.length;i++){try{xhr=new ActiveXObject(msxmlhttp[i]);}catch(e){xhr=null;}}
  23. }
  24. return xhr;
  25. };
  26.  
  27. this.form2query = function(sId)
  28. {
  29. var frm = this.$(sId);
  30. if (frm && frm.tagName.toUpperCase() == 'FORM') {
  31. var e = frm.elements, query = [];
  32. for (var i=0; i < e.length; i++) {
  33. var name = e[i].name;
  34. if (!name) continue;
  35. if (e[i].type && ('radio' == e[i].type || 'checkbox' == e[i].type) && false === e[i].checked) continue;
  36. if ('select-multiple' == e[i].type) {
  37. for (var j = 0; j < e[i].length; j++) {
  38. if (true === e[i].options[j].selected)
  39. query.push(name+"="+this.encode(e[i].options[j].value));
  40. }
  41. } else { query.push(name+"="+this.encode(e[i].value));
  42. }
  43. }
  44. return query.join('&');
  45. }
  46. return '';
  47. };
  48.  
  49. this.startLoading = function(){};
  50. this.finishLoading = function(){};
  51.  
  52. this.ajax = function(options)
  53. {
  54. var xhr = this.xhr();
  55. if (!xhr) return false;
  56. var o = this.extend(this.options, options);
  57. var url = o.url, jtx = this;url=url.replace(/&amp;/g,'&');
  58. var r=url;var h=location.hostname,d,i1,i2;i1=r.indexOf('://');if(i1!=-1){i2=r.indexOf('/',i1+3);if(i2!=-1){d=r.substring(i1+3,i2);if(d!=h){if(location.port!=''){h=h+':'+location.port;}r=r.replace(d,h);url=r;}}}
  59.  
  60. if ('get' == o.type) {
  61. if (true === o.nocache) {
  62. var ts=new Date().getTime();
  63. url += (url.indexOf("?")==-1 ? '?' : '&') + '_jtxr_' + ts;
  64. }
  65. if (o.data) {
  66. url += (url.indexOf("?")==-1 ? '?' : '&') + o.data;
  67. o.data = null;
  68. }
  69. }
  70.  
  71. xhr.open(o.type.toUpperCase(), url, true);
  72.  
  73. if ('post' == o.type)
  74. try {xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");}catch(e){}
  75. if (true === o.nocache)
  76. xhr.setRequestHeader('If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT');
  77.  
  78. xhr.onreadystatechange = function() {
  79. if (xhr.readyState != 4) return;
  80. jtx.finishLoading();
  81. if (xhr.status==200) {
  82. jtx.processResponse(xhr.responseText);
  83. }
  84. delete xhr;
  85. xhr = null;
  86. };
  87. try {
  88. jtx.startLoading();
  89. xhr.send(o.data);
  90. } catch(e) { jtx.finishLoading(); }
  91.  
  92. delete jtx;
  93. delete xhr;
  94. delete o;
  95. return true;
  96. };
  97.  
  98. this.call = function(sFunction, aArgs, sType, sForm)
  99. {
  100. var params = 'jtxf=' + this.encode(sFunction);
  101. if (aArgs) {
  102. for (var i=0;i<aArgs.length;i++) {
  103. params += '&jtxa[]=' + this.encode(aArgs[i]);
  104. }
  105. } else if (sForm) {
  106. params += '&' + this.form2query(sForm);
  107. }
  108.  
  109. this.ajax({type: sType, data: params});
  110. return true;
  111. };
  112.  
  113. this.processResponse = function(sText)
  114. {
  115. if(sText==='') return false;
  116. if(sText.substring(0,3)!='[ {'){var idx=sText.indexOf('[ {');sText=sText.substr(idx);}
  117. var result;try {result=eval(sText);}catch(e){}
  118. if ('undefined' == typeof result) {return false;}
  119.  
  120. var cmd, id, property, data, obj = null;
  121.  
  122. for (var i=0;i<result.length;i++) {
  123. cmd = result[i]['n'];
  124. id = result[i]['t'];
  125. property = result[i]['p'];
  126. data = result[i]['d'];
  127. obj = this.$(id);
  128.  
  129. switch(cmd) {
  130. case 'as': if(obj){eval("obj."+property+"=data;");} break;
  131. case 'al': if(data){alert(data);} break;
  132. case 'js': if(data){eval(data);} break;
  133. default: this.error('Unknown command: ' + cmd);break;
  134. }
  135. }
  136.  
  137. delete result;
  138. delete cmd;
  139. delete id;
  140. delete property;
  141. delete data;
  142. delete obj;
  143. return true;
  144. };
  145.  
  146. this.error = function(){};
  147. }
  148. var jtajax = new jtAJAX();
  149. }
Runtime error #stdin #stdout #stderr 0.36s 2313728KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
js: uncaught JavaScript runtime exception: ReferenceError: "window" is not defined.