前端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Show page</title> </head> <body> <h1>show page content1</h1> <script> function myFunction(str){ //定义处理数据的函数 document.write(str + " world"); } </script> <script type='text/javascript' src='/static/js/myfunction.js'></script> <!--<script type='text/javascript' src='http://127.0.0.1:8080/traffic/qlake/v1/jsonp?callback=myFunction'></script>--> </body> </html> |
/static/js/myfunction.js 文件
1 2 3 4 5 |
/** * Created by lee on 2017/4/13. */ myFunction('hello'); |
jsonp方式
1 2 3 4 |
@RequestMapping("/jsonp") public String jsonp(@RequestParam(name = "callback", defaultValue = "") String callback) { return callback + "(\"hello\")"; } |
转载请注明:Imekaku-Blog » jsonp使用