[sourcecode language="plain"]
//主类
class Test {

// 通过获取div的id改变div内容
static function setContent(id,content) {
var d = js.Lib.document.getElementById(id);
if( d == null )
js.Lib.alert("Unknown element : "+id);
d.innerHTML = content;
}

// 创建一个链接
static function makeLink(title,code) {
return ''+title+'';
}

// 点击链接以后触发的事件
static function click() {
//setContent("main","Congratulations !");
//同步加载
// setContent("main",haxe.Http.requestUrl("data.xml"));
//异步加载
var r = new haxe.Http("data.xml");
//给链接加参数
//r.setParameter("param","value")
r.onError = js.Lib.alert;
r.onData = function(r) { setContent("main",r); }
r.request(false);//true for POST
}

static function main() {
// 初始化
setContent("main",makeLink("click here","Test.click()"));
}
}
[/sourcecode]

对应的html文件
[sourcecode]

Haxe AJAX



[/sourcecode]

对应的data.xml
[sourcecode]
Hello World
[/sourcecode]