Request.JSON以页面加载运行

时间:2013-01-03 08:07:07

标签: json mootools

http://mootools.net/demos/?demo=Request.JSON

点击load JSON Data时加载JSON数据。

是否可以在页面打开时加载此数据(类似onload的功能)

1 个答案:

答案 0 :(得分:2)

<head>
    <script type="text/javascript">
    window.addEvent("domready",function(){
        var request = new Request.JSON({
            url: '/echo/json/',
            onRequest: function(){
                gallery.set('text', 'Loading...');
            },
            onComplete: function(jsonObj) {
                gallery.empty();
                addImages(jsonObj.previews);
            },
            data: { // our demo runner and jsfiddle will return this exact data as a JSON string
                json: JSON.encode(data)
            }
        }).send();

    });
    </script>
</head>