ajax异步请求实现 返回数据之前加载loading图标
<!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>
Dcr163的博客
http://dcr163.cn/87.html(转载时请注明本文出处及文章链接)