zoukankan      html  css  js  c++  java
  • 一例jsonp跨域访问

    对于网站A,有一链接 '/auth/list',返回json数据

    {"value": [{"id": 1, "link": "gd/list", "description": "u67e5u8be2u5546u54c1u4e3bu6570u636e", 
    "role": 1, "fullpath": "goodsinfo/Goodsinfo/gdlist", "ismenu": 0, "menulevel": 0, "saiwa": 1, "authno": 101},
    {"id": 2, "link": "gd/insert", "description": "u6dfbu52a0u5546u54c1u4e3bu6570u636e",
    "role": 1, "fullpath": "goodsinfo/Goodsinfo/gdinsert", "ismenu": 0, "menulevel": 0, "saiwa": 1, "authno": 102}]}

    网站b某页面下可以这样写jsonp get请求

    <script>
        var anothersite = "http://"+'127.0.0.1:8989';
        function usejsonp() {
            var wenwa =  anothersite;
            alert(wenwa);
            $.ajax({
                url:anothersite+'/auth/list',
                type:'get',
                dataType:"json",
                jsonp: "callback",
                //jsonpCallback:'showdata',
                success:function (data) {
                    console.log("可能已经成功");
                    console.log(data)
                }
            })
        }
    </script>

     这样,网站b也可以拿到页面最开始展示的json数据

  • 相关阅读:
    初学版本控制更新Version control
    关于函数式编程(Functional Programming)
    Annotation
    Container 、Injection
    Build Tools
    Version Control
    URL和URI的区别
    函数式编程语言
    HTTP协议的简单解析
    Windows10安装MySQL8.0
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/10958133.html
Copyright © 2011-2022 走看看