一、豆瓣获取数据

5CYCJOR%2VQB{R~A}YGJO53.png

HTML

  1. <div class="center">
  2. <div class="left">
  3. </div>
  4. <div class="right">
  5. </div>
  6. </div>

script

  1. <script>
  2. var url_list = "http://192.168.4.18:8000/"
  3. ajax({
  4. url: url_list,
  5. method: "get",
  6. success: res => {
  7. var arr = [];
  8. arr.push(...res.result)
  9. arr.forEach((item, index) => {
  10. var html = `
  11. <div class="item">
  12. <span class="num">${index + 1}</span>
  13. <img src=${item.pic} alt="">
  14. <div class="p">
  15. <a href="#" class="title">${item.title}</a>
  16. <p class="raiting">${item.raiting}</p>
  17. <p class="slogo">${item.slogo}</p>
  18. <p class="evaluate">${item.evaluate}</p>
  19. <p class="labels">${item.labels}</p>
  20. </div>
  21. </div>
  22. `
  23. $(".left").append(html)
  24. })
  25. }
  26. })
  27. </script>
  28. <script>
  29. var url = "http://192.168.4.18:8000/ad"
  30. ajax({
  31. url: url,
  32. method: "get",
  33. success: res => {
  34. var obj = res.result
  35. for(let i in obj){
  36. var {title,poster,erweima,logo,labels}=obj;
  37. }
  38. var ad=labels.join("")
  39. var htmls= `
  40. <div class="items">
  41. <p class="titles">${title}</p>
  42. <img src=${poster} class="poster">
  43. <div class="footer">
  44. <div class="div">
  45. <img src=${erweima} class="erweima">
  46. </div>
  47. <div class="div">
  48. <img src=${logo} class="logo">
  49. </div>
  50. <div class="divs">
  51. <p class="ad">${ad.substring(0,2)}</p>
  52. <p class="ads">${ad.substring(2)}</p>
  53. </div>
  54. </div>
  55. </div>
  56. `
  57. $(".right").append(htmls)
  58. }
  59. })
  60. </script>

js

  1. function ajax({
  2. method,
  3. url,
  4. success
  5. }) {
  6. var xhr = new XMLHttpRequest()
  7. xhr.open(method, url, true)
  8. xhr.send()
  9. xhr.onreadystatechange = function () {
  10. if (xhr.status == 200 && xhr.readyState == 4) {
  11. var res = JSON.parse(xhr.responseText)
  12. success(res)
  13. }
  14. }
  15. }

css

  1. *{
  2. margin: 0;
  3. padding: 0;
  4. }
  5. .center{
  6. margin-top: 50px;
  7. width: 1000px;
  8. margin-left: auto;
  9. margin-right: auto;
  10. display: flex;
  11. }
  12. .left{
  13. flex:5;
  14. }
  15. .item{
  16. display: flex;
  17. border-top: 1px dashed #ccc;
  18. padding: 20px;
  19. }
  20. .item img{
  21. margin-left: 10px;
  22. height: 180px;
  23. }
  24. .p{
  25. margin-left: 10px;
  26. }
  27. .title{
  28. font-size: 18px;
  29. color: rgb(36, 81, 139);
  30. text-decoration: none;
  31. }
  32. .title:hover{
  33. background-color: rgb(36, 81, 139);
  34. color: white;
  35. }
  36. .right{
  37. margin-left: 20px;
  38. flex: 2;
  39. }
  40. .titles{
  41. font-size: 14px;
  42. color: darkgray;
  43. }
  44. .poster{
  45. width: 100%;
  46. margin-top: 10px;
  47. }
  48. .footer{
  49. height: 100px;
  50. margin-top: 10px;
  51. position: relative;
  52. display: grid;
  53. grid-template-columns: 100px 90px auto;
  54. grid-template-rows: 100px;
  55. justify-items: center;
  56. align-items: center;
  57. background-color: rgb(243, 243, 243);
  58. }
  59. .divs{
  60. justify-self: start;
  61. }
  62. .erweima{
  63. height: 90px;
  64. }
  65. .logo{
  66. height: 100px;
  67. }
  68. .ads{
  69. padding-top: 5px;
  70. font-size: 13px;
  71. }
  72. .ad{
  73. font-size: 20px;
  74. }