Skip to content

Update: 5-network/05-fetch-crossorigin #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file removed 5-network/04-fetch-crossorigin/[email protected]
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ try {

说真的,在这说点儿题外话,讲讲它的历史。

**来自一个网站的脚本无法访问其他网站的内容**
**多年来,来自某个网站的脚本无法访问另一个网站的内容。**

这个简单有力的规则是互联网安全的基础。例如,来自 `hacker.com` 页面的脚本无法访问 `gmail.com` 上的用户邮箱。基于这样的规则,人们感到很安全。

在那时候,JavaScript 只是一种装饰网页的玩具语言而已,它并没有任何特殊的执行网络请求的方法。

但是网络开发人员需要更多的控制权。人们发明了各种各样的技巧去解决它
但是网络开发人员需要更多的控制权。人们发明了各种各样的技巧去突破它的限制

### 使用 forms

Expand All @@ -52,7 +52,7 @@ try {

因此,即使没有网络方法,它也可以向其他网站发起一个 GET/POST 请求。但是由于禁止从其他网页读取 `<iframe>` 的内容,因此就无法读取响应。

所以我们可以看到,forms 可以在任意位置发送数据,但是不能接受响应内容。确切地说,还是有一些技巧能够解决这个问题的(iframe 和页面中都需要添加特殊脚本),不过我们还是让这些老古董代码不要再出现了吧。
正如所见,forms 可以在任意位置发送数据,但是不能接受响应内容。确切地说,还是有一些技巧能够解决这个问题的(iframe 和页面中都需要添加特殊脚本),不过我们还是让这些老古董代码不要再出现了吧。

### 使用 scripts

Expand Down Expand Up @@ -84,7 +84,7 @@ try {
temperature: 25,
humidity: 78
});

```
4. 当远端脚本加载并执行的时候,`gotWeather` 函数被调用,并且因为它是我们的函数,我们就有需要的数据了。


Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 5-network/05-fetch-crossorigin/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.