标签:eject heat eth var sheet .com mod bsp alt
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title> 豆瓣 </title> <script src="node_modules/jquery/dist/jquery.min.js"></script> <link rel="stylesheet" href="http://at.alicdn.com/t/font_5vya30kj3lyp66r.css"> <link rel="stylesheet" href="css/douban.css"> </head> <body> <div id="box"> 正在加载 </div> <ul id="list"> </ul> </body> <script src="js/ajax.js"></script> <script> var url = "https://api.douban.com/v2"; var ui = "/movie/in_theaters"; var _data = url+ui; var method = "GET"; // $.Deferred().promise() var str = ""; handleAjax(url,_data,method).done(function (data) { $("#box").hide(); var data = data.subjects; data.forEach(function (el,i) { str+=`<li data-star="${data[i].rating.stars}"><img src="${data[i].images.small}" alt="" /><span>${data[i].title}</span></li>` }); $("#list").html(str); }) </script> </html>
function handleAjax(url,_data,method) { return ajax(url,_data,method).then(function (res) { if(res){ return res }else{ return $.Deferred().reject(res.msg) } },function(err) { console.log(err.status); }) } function ajax(url,_data,method) { return $.ajax({ url: ‘ajax.php‘, type: method, dataType: ‘JSON‘, data: {data:_data}, beforeSend:function (argument) { $("#box").show(); } }) }
标签:eject heat eth var sheet .com mod bsp alt
原文地址:http://www.cnblogs.com/magicyangmei/p/6143523.html