前端
<!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 文件
/** * Created by lee on 2017/4/13. */ myFunction('hello');
jsonp方式
@RequestMapping("/jsonp") public String jsonp(@RequestParam(name = "callback", defaultValue = "") String callback) { return callback + "(\"hello\")"; }