1、ajax--get请求
<h1>get请求</h1>
<button onclick="fn()">请求</button>
<script>
function fn(){
// console.log(0000)
ajax--get请求
var xhr=new XMLHttpRequest()
url="/get1"//chuan参数给后端
xhr.open("GET",url)
xhr.send()
xhr.onreadystatechange=()=>{
if(xhr.readyState==4&&xhr.status==200){
console.log(xhr.responseText)
}
}
}
2、axios----get请求
get请求后端,会把数据拼接到url中,不安全,但是速度快
controller.home里面去写
var k=this.ctx.request.query即:
在前端页面上写
<input type="text" id="search">
<button onclick="fn()">搜索</button>
<script src='https://s1.pstatp.com/cdn/expire-1-M/axios/0.19.2/axios.js'></script>
<script>
function fn(){
var searvalue=document.getElementById("search").value
//axios--get
var url='/get1'
axios(url,{params:{count:20,keywords:searvalue}})
.then(res=>{
console.log(res)
})
}
</script>
结果:
3、浏览器的地址栏只能发送get请求
接受的数据会直接读取渲染,失败则会下载下来
4、a标签的href属性也只能发送get请求,并且是点击事件触发了,默认事件才会发送get请求,会发生网络请求,给href网址接受的数据会直接读取渲染,失败则会下载下来
<a href="http://192.168.154.1:7001/get1">a标签</a>
5、img--src
只能发送get请求,返回的数据渲染成图片,如果非图片编码就会碎裂
6、link--href
只能发送get请求,返回的数据按照功能的使用
7、表单--form---action对应的url
发送get 、post/delete等等给action属性对应的url发送请求
(1)用户点击提交按钮或者是触发表单的提交事件
(2)get请求会把form中的数据全部解析为url的querystring
(3)返回的数据同a标签一样使用