1. <?php
    2. if($_GET['action'] == 'getJSON') {
    3. helper_output::json(array('description'=>'我是JSON数据', 'datalist' => array('数据1', '数据2', '数据3')));
    4. } else if($_GET['action'] == 'getHTML') {
    5. helper_output::html('<div>我是HTML</div>');
    6. } else if($_GET['action'] == 'getdata') {
    7. helper_output::xml('我是XML数据');
    8. }
    9. ?>
    10. <script>
    11. var x = new Ajax();
    12. x.getJSON('forum.php?mod=misc&action=getJSON', function(s) {
    13. //JSON数据错误时,s为null
    14. if(s !== null) {
    15. //code
    16. alert(s);
    17. }
    18. });
    19. var x2 = new Ajax();
    20. x2.getHTML('forum.php?mod=misc&action=getHTML', function(s) {
    21. //code
    22. alert(s);
    23. });
    24. var x3 = new Ajax();
    25. x3.get('forum.php?mod=misc&action=getdata', function(s){
    26. alert(s);
    27. });
    28. </script>