Last active
August 29, 2015 14:11
-
-
Save AndrewStanton94/0ad24473e244efdb2e1e to your computer and use it in GitHub Desktop.
Shows how ajaxGet can be used for .txt & .php. Full example. getdir can be called by passing its url as first arg of ajaxget.js same with d3sg.js
This file contains 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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<title>ds3e</title> | |
<meta charset = 'UTF-8'> | |
<link rel='icon' href='favicon.ico'> | |
<script src='lib/ajaxget.js'></script> | |
<script src='ds3e.js'></script> | |
</head> | |
<body> | |
<h1>Dynasite 3e – First AJAX</h1> | |
<div id=grabdiv> | |
AJAX uploads go here. | |
</div> | |
<div id='grabphpdiv'> | |
AJAX uploads from PHP go here. | |
</div> | |
</body> | |
</html> |
This file contains 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
function AjaxGet(URL, callback) | |
{ | |
var ajaxObj = new XMLHttpRequest(); | |
ajaxObj.open("GET", URL, true); // The True implies asynchronous | |
ajaxObj.onreadystatechange = function() | |
{ | |
if (ajaxObj.status == 200) | |
if (ajaxObj.readyState == 4) | |
callback(ajaxObj.responseText); | |
}; | |
ajaxObj.send(null); | |
} |
This file contains 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
function grabber (response) { | |
document.getElementById('grabdiv').innerHTML = response; | |
} | |
function grabphp(response) { | |
document.getElementById('grabphpdiv').innerHTML = response; | |
} | |
AjaxGet('datafile.txt', grabber); | |
AjaxGet('api/ds3e.php', grabphp); |
This file contains 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
<?php echo "This text was requested by AJAX and ECHOed by ds3e.php"; ?> |
This file contains 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
function showFileNames (respose) { | |
console.log('respose = ' + respose); | |
namearray = respose.split(','); | |
console.log('namearray.length = ' + namearray.length); | |
for (var namepile="", i=0; i<namearray.length; i++) { | |
console.log('namearray[' + i + '] = ' + namearray[i]); | |
var ni = namearray[i]; | |
if (ni.endsWith('.htm') || ni.endsWith('.html') || ni.endsWith('.php') || ni.endsWith('.js') || ni.endsWith('.txt')) | |
{ | |
namepile = namepile + namearray[i] + "<br>"; | |
console.log('namepile#' + i + ' = ' + namepile); | |
} | |
} | |
document.getElementById('filenamesdiv').innerHTML = namepile; | |
} | |
AjaxGet('api/getdir.php', showFileNames); |
This file contains 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
<?php | |
$dir = opendir('../'); | |
if (!$dir) {echo "Error: could not open directory"; exit;} | |
while ($name=readdir($dir)) { | |
if (!is_dir($name) && !is_executable($name)) | |
echo "$name"; | |
} | |
echo "-\r\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment