GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — JSONP JSONP
JoyChou edited this page
代码很简单: 当有接口返回了Object(比如JSONObject或者JavaBean,但是不支持String),只要在参数中加入 虽然上面代码指定了response的 设置 并且还会判断callback的参数只是否是有效的,代码如下: 返回: 使用 在Spring Framework 5.1,移除了
使用ajax的jsonp调用方式代码: <html> <head> <meta charset="UTF-8" /> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> </head> <body> <script language="JavaScript"> $(document).ready(function() { $.ajax({ url:'http://localhost:8080/jsonp/advice', dataType:'jsonp', success:function(data){ alert(data.name) } }); }); </script> </body> </html> script src方式代码: 有时候开发同学为了测试方便,JSONP接口能直接访问,不直接访问做了Referer限制。正常来讲,前端发起的请求默认都会带着Referer,所以简单说下如何绕过空Referer。 <html> <meta name="referrer" content="no-referrer" /> <script> function test(data){ alert(data.name); } </script> <script src=http://localhost:8080/jsonp/emptyReferer?callback=test></script> </html> <iframe src="javascript:'<script>function test(data){alert(data.name);}</script><script src=http://localhost:8080/jsonp/emptyReferer?callback=test></script>'"></iframe> Clone this wiki locally |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |