自己实现一个简单的 JSONP
定义一个success回调函数:
通过<script>标签,请求接口数据:
示例代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="http://ajax.frontend.itheima.net:3006/api/jsonp?callback=success&name=ls&age=14"></script> </head> <body> </body> <script> function success(data) { console.log('JSONP响应回来的数据是:'); console.log(data); } </script> </html>