可以发送不同源请求的方式


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>尝试找到一种可以发送不同源请求的方式</title>
<!-- link 真正的定义:链入一个文档,通过 rel 属性申明链入的文档与当前文档之间的关系 -->
<!-- <link rel="stylesheet" href="nprogress.css"> -->
</head>
<body>
<!-- <img src="http://ww1.sinaimg.cn/large/006ThXL5ly1fj8w5i2onyj302u02umwz.jpg" alt=""> -->
<script>

// 请求一个不同源的地址实际上就是我们所说的跨域请求

// 当前页面访问地址:http://day-12.io/12-cross-origin.html
// 希望被请求的地址:http://locally.uieee.com/categories
//
// 校验目标:1 能发出去,2 能收回来

// img link script iframe
//
// ## 1. img
// 可以发送不同源地址之间的请求
// 无法拿到响应结果
// var img = new Image()
// img.src = 'http://locally.uieee.com/categories'

// ## 2. link
// 可以发送不同源地址之间的请求
// 无法拿到响应结果
// var link = document.createElement('link')
// link.rel = 'stylesheet'
// link.href = 'http://locally.uieee.com/categories'
// document.body.appendChild(link)

// ## 3. script
// 可以发送不同源地址之间的请求
// 无法拿到响应结果
// 借助于能够作为 JS 执行
var script = document.createElement('script')
script.src = 'http://localhost/time2.php'
document.body.appendChild(script) // 开始发起请求

// 相当于请求的回调
function foo (res) {
console.log(res)
}

// console.log(a)

</script>
</body>
</html>

转载于:https://www.cnblogs.com/lujieting/p/10291410.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值