1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | <! DOCTYPE html> < html > < body > < h1 >XMLHttpRequest 对象</ h1 > < button type="button" onclick="loadDoc()">国家接口</ button > < button type="button" onclick="loadDoc1()">揽收仓接口</ button > < button type="button" onclick="loadDoc2()">产品接口</ button > < p id="demo"></ p > < script > function loadDoc() { var xhr = new XMLHttpRequest(); xhr.open('post', 'https://xxxx/api/values/FindCountryList', true); var params = { 'countryId': '1', }; xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(JSON.stringify(params)); xhr.onload = function(e) { var xhr = e.target; console.log(xhr.responseText);} } function loadDoc1() { var xhr = new XMLHttpRequest(); xhr.open('post', 'https://xxx/api/values/FindWarehouseList', true); var params = { "warehouseCode":"03,04" }; xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(JSON.stringify(params)); xhr.onload = function(e) { var xhr = e.target; console.log(xhr.responseText);} } function loadDoc2() { var xhr = new XMLHttpRequest(); xhr.open('post', 'https://xxx/api/values/FindProductList', true); var params = { "Platform":"6" }; xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(JSON.stringify(params)); xhr.onload = function(e) { var xhr = e.target; console.log(xhr.responseText);} } </ script > </ body > </ html > |
将自己的接口和参数替换到相应位置,生成html页面,打开页面,打开调试工具,点击对应按钮,如果控制台有接口返回,则说明该接口可跨域。
Tip:前提是,你请求的接口不应该是本地接口,否则验证没有任何意义
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器