Blogger Information
Blog 62
fans 3
comment 1
visits 29695
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
ajax操作与模块成员相关操作
kiraseo_wwwkiraercom
Original
370 people have browsed it

xhr查询

代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>xhr查询</title>
  8. </head>
  9. <body>
  10. <button onclick="getImgs(this)">xhr查询</button>
  11. <script>
  12. function getImgs(btn){
  13. let url ='https://jsonplaceholder.typicode.com/albums/1/photos';
  14. // 创建对象:
  15. const xhr = new XMLHttpRequest();
  16. // 响应类型
  17. xhr.responseType = "json";
  18. // 配置参数
  19. xhr.open("GET", url, true);
  20. // 请求回调
  21. xhr.onload = () => console.log(xhr.response);
  22. // 请求回调
  23. xhr.onload = () => console.log(xhr.response);
  24. // 失败回调
  25. xhr.onerror = () => console.log("Error");
  26. // 发起请求
  27. xhr.send(null);
  28. }
  29. console.log("xhr方式");
  30. </script>
  31. </body>
  32. </html>

演示截图

fetch异步

代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>fetch异步</title>
  8. </head>
  9. <body>
  10. <button onclick="getComments(this)">fetch获取评论</button>
  11. <script>
  12. console.log("fetch异步");
  13. function getComments(btn){
  14. let url = 'https://jsonplaceholder.typicode.com/posts/1/comments';
  15. fetch(url)
  16. .then( function (response){
  17. return response.json();
  18. })
  19. .then( function (json){
  20. console.log(json);
  21. })
  22. };
  23. </script>
  24. </body>
  25. </html>

演示截图

代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>模块成员导出与导入,别名使用场景与命名空间演示 </title>
  8. </head>
  9. <body>
  10. <!-- 模块成员导出与导入,别名使用场景与命名空间演示 -->
  11. <script type="module">
  12. // <!-- export { username as studyName, getStudent,studyURL}; -->
  13. import * as studyNews from './modules/t1.js';
  14. console.log(studyNews);
  15. console.log(studyNews.studyName);
  16. console.log(studyNews.getStudent(studyNews.studyName,'61952'));
  17. console.log(studyNews.studyURL);
  18. </script>
  19. </body>
  20. </html>
  1. // 默认成员与非默认成员的导出
  2. let username = '牛老师';
  3. function hello(username) {
  4. return `Hello, ${username}`;
  5. }
  6. let useremail = 'admin@php.cn';
  7. // 私有成员, 不对外
  8. let sex = 'male';
  9. // 将邮箱 useremail 做为默认导出 , 起一个特殊的别名 default
  10. export { username, hello, useremail as default };

演示截图

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post