Advertisement
FlyFar

functions.js

Jul 19th, 2023
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.86 KB | Cybersecurity | 0 0
  1. function showMessage(msg, closeAfter){
  2.     document.getElementById("error").innerHTML = msg;
  3.     if(closeAfter !== undefined){
  4.         setTimeout(function(){
  5.             document.getElementById("error").innerHTML = "";
  6.         },closeAfter);
  7.     }
  8. }
  9.  
  10. function getResponse(adr, callback, timeoutCallback, timeout, method){
  11.     if(timeoutCallback === undefined) {
  12.         timeoutCallback = function(){
  13.             showMessage("error loading "+adr);
  14.         };
  15.     }
  16.     if(timeout === undefined) timeout = 8000;
  17.     if(method === undefined) method = "GET";
  18.     var xmlhttp = new XMLHttpRequest();
  19.     xmlhttp.onreadystatechange = function() {
  20.         if(xmlhttp.readyState == 4){
  21.             if(xmlhttp.status == 200){
  22.                 showMessage("");
  23.                 callback(xmlhttp.responseText);
  24.             }
  25.             else timeoutCallback();
  26.         }
  27.     };
  28.     xmlhttp.open(method, adr, true);
  29.     xmlhttp.send();
  30.     xmlhttp.timeout = timeout;
  31.     xmlhttp.ontimeout = timeoutCallback;
  32. }
Tags: func
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement