Sometimes I have to stick a potato in my mouth before saying anything. Or take a potato in each hand before blogging anything.
In previous post about loading files with javascript, I said that it was not possible with Ajax, it was necessary to use iframes, etc, etc … Filthy Lie! Of course you can, and is much easier.
The code for loadinga Lisp program, compile it and run it would be:
<html>
<head>
<script type="text/javascript" src="lisp2js.js"></script>
<script id="head_js" type="text/javascript"></script>
<script type="text/javascript">
function load_file (file) {
var req = new XMLHttpRequest();
req.open('GET', file, false);
req.send(null);
if (req.status == 200) {
var lisp_code = req.responseText;
var js_code = string2js(lisp_code);
document.getElementById('head_js').text = js_code;
}
}
</script>
</head>
<body onLoad="load_file('my_program.lisp'); init();">
</body>
</html>
This would be the synchronous version, but it can also be done asynchronously. You can see more examples in Using XMLHttpRequest.
Advertisement
Pingback: Running Gacela programs in the browser | Between parentheses