zoukankan      html  css  js  c++  java
  • day 37 ajax跨域 浏览器同源测略

              

    浏览器的同源策略

    允许跨域:

    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.ioloop
    import tornado.web
    import io
    
    
    class 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.ioloop
    import tornado.web
    import io
    import check_code
    
    class 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
  • 相关阅读:
    ClickHouse之访问权限控制
    ClickHouse之集群搭建以及数据复制
    ClickHouse之简单性能测试
    ClickHouse之初步认识
    从完整备份恢复单个innodb表
    MHA快速搭建
    MySQL 5.7最新版本的2个bug
    Greenplum各种Tips(不定时更新)
    MySQL 5.7贴心参数之binlog_row_image
    TCP窗口机制与流量控制
  • 原文地址:https://www.cnblogs.com/ezway/p/7183445.html
Copyright © 2011-2022 走看看