$.ajax({

url, 请求的url地址

type, 请求的方式

data,

dataType, 请求的数据类型

success:res=>{ 成功的回调

console.log(res)

}

})

jquery-ajax中 get传值问号后面的值,可以放在data属性中

  1. <script>
  2. var url ="http://192.168.4.18:3000/search";
  3. $.ajax({
  4. url,
  5. type:"get",
  6. data:{
  7. keywords:"你"
  8. },
  9. success:res=>{
  10. console.log(res);
  11. }
  12. })
  13. // var url ="http://192.168.4.18:8000/";
  14. // $.ajax({
  15. // url,
  16. // type:"get",
  17. // data:{
  18. // },
  19. // dataType,
  20. // success:res=>{
  21. // console.log(res);
  22. // }
  23. // })
  24. </script>

jQuery-ajax的写法:

1 、

  1. <script>
  2. var url ="http://192.168.4.18:3000/search?keywords=你";
  3. $.get(url).then(res=>{
  4. console.log(res)
  5. })
  6. </script>

2 、

  1. <script>
  2. var url ="http://192.168.4.18:3000/search?keywords=你";
  3. $.get(url,res=>{
  4. console.log(res)
  5. })
  6. </script>