vue 跨域XMLHttpRequest
vue 跨域 使用XMLHttpRequest 亲测好使
let url='http://127.0.0.1:9000/pssnotifyyb?b=1'//url='https://api.j4u.ink/v1/store/other/proxy/remote/moyu.json'var xhr=new XMLHttpRequest()xhr.open('GET',url,true)//第三个参数是是否异步请求,默认true xhr.onreadystatechange=function(){if(xhr.readyState===XMLHttpRequest.DONE && xhr.status===200){console.log('请求成功',JSON.parse(xhr.responseText));}}.bind(this)xhr.send('ss')
XMLHttpRequest 是怎么回事
XMLHttpRequest(XHR)底层是基于HTTP协议实现的。 XMLHttpRequest对象有一个readyState属性,表示XMLHttpRequest对象的状态。
- 当readyState为0时,XMLHttpRequest对象已经创建,但还未初始化。
- 当readyState为1时,XMLHttpRequest对象已经调用open()方法,但还未发送请求。<