一例jsonp跨域访问
对于网站A,有一链接 '/auth/list',返回json数据
{"value": [{"id": 1, "link": "gd/list", "description": "\u67e5\u8be2\u5546\u54c1\u4e3b\u6570\u636e",
"role": 1, "fullpath": "goodsinfo/Goodsinfo/gdlist", "ismenu": 0, "menulevel": 0, "saiwa": 1, "authno": 101},
{"id": 2, "link": "gd/insert", "description": "\u6dfb\u52a0\u5546\u54c1\u4e3b\u6570\u636e",
"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数据