mootools-ajax

mootools如何使用ajax

ajax.php

<?php
sleep( 1 ); //延时 1秒
header('Content-Type:text/html;charset=utf8');//防止中文信息有乱码
header('Cache-Control:no-cache');//防止浏览器缓存,导致按F5刷新不管用
echo('哈哈哈 欢迎来到 PHP记事本 ');

ajax.html

<!doctype html>
<html>
    <head>
        <script type="text/javascript" src="./js/mootools-core-1.4.5-full-compat.js">
        </script>
    </head>
    <body>
<div id="xlxzLink" style="height:100px;width:100px;background:red">
</div>

<textarea id=xlxzcontent cols=80 rows=20>
</textarea>

<script language="javascript" type="text/javascript">
var myElement = document.id('xlxzcontent');

var myRequest = new Request({
    url: 'ajax.php',
    method: 'get',
    onRequest: function(){
        myElement.set('text', '请少等片刻');
    },
    onSuccess: function(xlxzText){
        myElement.set('text', xlxzText);
    },
    onFailure: function(){
        myElement.set('text', '不好意思,请求失败');
    }
});

document.id('xlxzLink').addEvent('click', function(event){
    event.stop();
    myRequest.send();
});

</script>

    </body>

</html>