base元素影响ajax请求地址演示页面
展示
//zxx: 打开开发者工具,点击按钮,查看网络请求
代码
-
HTML:
<base href="https://www.cssworld.cn/"> <button type="primary" id="button" class="ui-button">请求图片'/assets/example.jpg'</button> <p id="output"></p>
-
JS:
button.addEventListener('click', function () { fetch('/assets/example.jpg').then(function (response) { return response.blob(); }).then(function (blob) { var img = document.createElement('img'); img.src = URL.createObjectURL(blob); output.append('img'); }).catch(function (e) { console.error(e); output.className = 'error'; output.textContent = e.message; }); });