day 37 ajax跨域 瀏覽器同源測略

來源:互聯網
上載者:User

標籤:color   creat   elf   alt   bsp   tee   efi   listen   jsonp   

          

瀏覽器的同源策略

允許跨域:

script

img

iframe

不允許跨域:

ajax

 跨域ajax

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Title</title></head><body>    <h1>T1</h1>    <input type="button" value="Ajax" onclick="AJAX();">    <input onclick="Jsonp();" type="button" value="Jsonp" >    <script type="text/javascript" src="/statics/jquery-3.1.1.js"></script>    <script>        function Jsonp() {            $.ajax({                url:‘http://127.0.0.1:8001/index‘,                dataType:‘jsonp‘,//                jsonp:‘callback‘,                jsonCallBack:‘func‘                            })        }        function ff(arg) {            console.log(arg)        }//        function Jsonp() {//           var tag=document.createElement(‘script‘);//            tag.src=‘http://127.0.0.1:8001/index‘;//            document.head.appendChild(tag);//            document.head.removeChild(tag);////        }        function AJAX() {            $.ajax({                url:‘/index‘,                type:‘post‘,                data:{‘k‘:‘1‘},                success:function (arg) {                    console.log(arg);                }            })        }    </script></body></html>
8002
#!/usr/bin/env python# -*- coding:utf-8 -*-import tornado.ioloopimport tornado.webimport ioclass IndexHandler(tornado.web.RequestHandler):    def get(self):        # callback=self.get_argument(‘callback‘)        # self.write(‘%s ([11,22,33]);‘ % callback)        self.render(‘index.html‘)    def post(self, *args, **kwargs):        self.write(‘t1t1t1t1t1posttttt‘)settings = {    ‘template_path‘: ‘views‘,    ‘static_path‘: ‘statics‘,    ‘static_url_prefix‘: ‘/statics/‘,}application = tornado.web.Application([    (r"/index", IndexHandler),], **settings)if __name__ == "__main__":    application.listen(8002)    tornado.ioloop.IOLoop.instance().start()
8002python
#!/usr/bin/env python# -*- coding:utf-8 -*-import tornado.ioloopimport tornado.webimport ioimport check_codeclass IndexHandler(tornado.web.RequestHandler):    def get(self):        self.write(‘ff([11,22,33,44])‘)    def post(self, *args, **kwargs):        self.write(‘ff([11,22,33,44])‘)settings = {    ‘template_path‘: ‘views‘,    ‘static_path‘: ‘statics‘,    ‘static_url_prefix‘: ‘/statics/‘,}application = tornado.web.Application([    (r"/index", IndexHandler),], **settings)if __name__ == "__main__":    application.listen(8001)    tornado.ioloop.IOLoop.instance().start()
8001python

 

day 37 ajax跨域 瀏覽器同源測略

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.