Last active
August 29, 2015 14:07
-
-
Save DanH42/6245755c9eb72513b3e6 to your computer and use it in GitHub Desktop.
A COBOL programmer tries to use AJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// IDENTIFICATION DIVISION. | |
// PROGRAM_ID. AJAX_EXAMPLE. | |
//* | |
// ENVIRONMENT DIVISION. | |
//* | |
// DATA DIVISION. | |
// WORKING_STORAGE SECTION. | |
var AJAX = null; | |
var URL = "EXAMPLE.TXT"; | |
var RESPONSE = ""; | |
var RETURN = ""; | |
//* | |
// PROCEDURE DIVISION. | |
// MAIN_LOGIC SECTION. | |
function SEND_REQ() { | |
RESPONSE = ""; | |
RETURN = ""; | |
AJAX = $.get(URL); | |
} | |
//* | |
function HAS_RESP() { | |
RETURN = "NO"; | |
if(AJAX.readyState == XMLHttpRequest.DONE) | |
{ | |
RETURN = "YES"; | |
} | |
} | |
//* | |
function GET_RESP() { | |
HAS_RESP(); | |
if(RETURN == "YES") { | |
RESPONSE = AJAX.responseText; | |
} | |
} | |
//* | |
function WAIT_FOR_RESP() { | |
//* WAIT FOR BETWEEN 5 AND 10 SECONDS | |
setTimeout(CHECK_FOR_RESP, | |
(5000 + (Math.random() * 5000))); | |
} | |
//* | |
function CHECK_FOR_RESP() { | |
HAS_RESP(); | |
if(RETURN == "YES") { | |
GET_RESP(); | |
DISPLAY_RESP(); | |
}else { | |
WAIT_FOR_RESP(); | |
} | |
} | |
//* | |
function DISPLAY_RESP() { | |
alert(RESPONSE); | |
} | |
//* | |
SEND_REQ(); | |
WAIT_FOR_RESP(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment