Ajhaxe
Ajax is a way to create web requests in order to update a part of a page content without to refresh all the page. It provides better ergonomics and an improved responsiveness to change interactively some of the web interface only.
Change interactively the content of an DOm element
package;
import js.Lib;
class Main
{
static function main()
{
}
static function updateContent(idElement, content)
{
var element = Lib.document.getElementById(idElement);
if(element == null) Lib.alert('Unknown elemen : '+idElement);
element.innerHTML = content;
}
}
}
We use the Lib class of js API in order to acces to an element with its ID .
var element = Lib.document.getElementById(idElement);
Test if the element exists, if not, display an alert window
if(element == null) Lib.alert('Unknown element : '+idElement);
Use innerHTML to change the content of an element.
element.innerHTML = content;
Compile :
haxe -js ../bin/ajhaxe.js -main Main
Create a web page and import your script :/p]
<html>
<head>
<title>AJAX with haXe</title>
</head>
<body>
<div id="HelloWorld">
</div>
<script type="text/javascript" src="ajhaxe.js"></script>
<div><a href="#" onclick="Main.updateContent('HelloWorld', 'Hello World !');">clique</a></div>
</body>
</html>
Demo
Download the source code to try it.
Contact
Follow me