13. Ajax请求限制同源限制

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 
 4 <head>
 5   <meta charset="UTF-8">
 6   <meta http-equiv="X-UA-Compatible" content="IE=edge">
 7   <meta name="viewport" content="width=device-width, initial-scale=1.0">
 8   <title>13Ajax请求限制同源限制</title>
 9 </head>
10 
11 <body>
12   <script>
13     /*
14       A网站的Ajax 只能往 A网站发送请求;
15 
16       什么是同源?
17         如果两个页面拥有相同的协议,域名和端口,那么这两个页面就属性于同一个源,其中只要一个不相同,就是不同源;
18         http://www.example.com/dir/page.html
19         域名:http://www.example.com
20         端口:80(默认)
21 
22         http://www.example.com/dir2/other.html:同源
23         http://example.com/dir/other.html: 不同源(域名不同)
24         http://www.example.com:81/dir2/other.html 不同源(端口不同)
25         https://www.example.com:81/dir2/other.html 不同源(协议不同)
26       
27       同源政策的目的
28         同源政策是为保存用户信息的安全,防止恶意的网站窃取数据,最初的同源政策是指A网站的客户端设置Cookie, B网站是不能访问的;
29 
30         随着互联网的发展,同源政策也越来越严格,在不同源的情况下,其中有一项规定就是无法向非同源地址发送Ajax请求,如果请求,浏览器就会报错;
31         
32     */
33   </script>
34 </body>
35 
36 </html>

 

posted @ 2022-01-08 17:43  sky-su  阅读(54)  评论(0)    收藏  举报