TypechoJoeTheme

Dcr163的博客

统计

ajax异步请求实现 返回数据之前加载loading图标

2016-07-28
/
0 评论
/
884 阅读
/
正在检测是否收录...
07/28
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax</title>
    <script src="js/jquery-1.9.1.min.js"></script>
</head>
<body>
    <div id="content">
        <ul id="item">
            <li>a</li>
            <li>a</li>
            <li>a</li>
            <li>a</li>
            <li>a</li>
        </ul>
        <p><button onclick="get();">Click Me</button></p>
        <p id="loading"></p>

    </div>
    <script>
        function get(){
            $.ajax({
                url:'index.php',
                type:'get',
                dataType:'json',
               timeout:5000,
                beforeSend:function(XMLHttpRequest){
                    $('#loading').html('<img src="img/loading.gif" alt="">');
                },
                success:function(msg){
                    $('#loading').empty();
                    if(msg){
                        $('#loading').html('ajax请求成功');

                    }
                }
            })
        }
    </script>
</body>
</html>
朗读
赞(0)
版权属于:

Dcr163的博客

本文链接:

http://dcr163.cn/87.html(转载时请注明本文出处及文章链接)

评论 (0)

人生倒计时

今日已经过去小时
这周已经过去
本月已经过去
今年已经过去个月

最新回复

  1. slot demo
    2025-01-13
  2. 陌天
    2025-01-09
  3. Kerrie Bostick
    2024-12-28
  4. Norma Gainey
    2024-09-21
  5. Amber Powlett
    2024-05-09

标签云